[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"Brian Karfunkel" <bkarfunkel@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Length for strings, ignoring SMCL tags |

Date |
Tue, 2 Dec 2008 13:43:27 -0800 |

Thanks for the help so far, it's at least nice to know I'm not overlooking something that's easy. I'm trying to output a series of locals in a nice tabular format, with pipes (i.e. "|") between columns and a line of hyphens separating rows. So, I iterate through a list of rows and columns, etc., and ultimately have a string that contains the text for each row. For a 2X2 with Hello, World, Longval, and a blank as values that would be something like: local row1 "| Hello{col 10} | World{col 18} |" local row2 "| Longval{col 10} | {col 18} |" which outputs to: | Hello | World | | Longval | | (note that in fixed-char font the column dividers line up). The point is, the width of each column is set by the longest value in that column. However, if, say, only one value in a column is very long, I don't want to have that whole column be very wide, but rather want something like this as output: -------------------- | Test | Table | -------------------- | tst2 | Table | ------------------------------------------------------------- | Really abnormally long cell value | Table | ------------------------------------------------------------- | Test | Table | -------------------- The problem is getting the right number of hyphens to be displayed; I want as many hyphens in the row-separators as there are characters in the output row, which is just the length of the row as it is displayed. I can work around it by keeping track of the length of each component of the output row (e.g. "Test" is 4, " | " is 3, "Table" is 5, etc.), but I was hoping there was a less cumbersome way, though it doesn't seem that there is. Anyway, thanks again for the help. -Brian On Tue, Dec 2, 2008 at 1:22 PM, Nick Cox <n.j.cox@durham.ac.uk> wrote: > My diagnosis is the same. Or at least, I battered my head against this > and could think of nothing that suited. > > However, let's go one step back. Why do you want this? > > Nick > n.j.cox@durham.ac.uk > > Austin Nichols > > Brian Karfunkel <bkarfunkel@gmail.com>: > According to -help extended_fcn- you can't use display directives with > "in" and "as": > > display in smcl "{err}hello" > loc g: display in smcl "{err}hello" > di strlen(`"`:display in smcl "{err}hello"'"') > > which is unfortunate for your particular example. So you are stuck > removing all {smcl} before computing length--and during that process > counting spaces if you want them. > > On Tue, Dec 2, 2008 at 3:58 PM, Brian Karfunkel <bkarfunkel@gmail.com> > wrote: > >> Is there a way to get the length of a string while ignoring any SMCL >> tags in the string? >> >> In other words, I have "{err}hello", and I want the length of "hello", >> since the "{err}" tag doesn't affect the length as outputted. >> >> I've tried the following: >> >> strlen(`"`: display "{err}hello"'"') >> >> and variations thereof, but nothing seems to work. If there is a >> solution, it would also be helpful to know how it would treat "{col >> 30}hello" and "{space 20}hello", for example, in terms of whether the >> columns/spaces that are inserted are counted in the length (i.e. >> whether it is literally the number of characters of the line on the >> screen as displayed or if it is just the length of the string you'd >> get if you, say, -regexr-ed out all the tags in braces). > > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/statalist/faq > * http://www.ats.ucla.edu/stat/stata/ > -- Brian Karfunkel Research Fellow Stanford Law School Crown Quadrangle 559 Nathan Abbott Way Stanford, California 94305 +1.650.721.5694 (office) | +1.978.886.1607 (mobile) bkarfunkel@gmail.com * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**Re: st: Length for strings, ignoring SMCL tags***From:*Jeph Herrin <junk@spandrel.net>

**Re: st: Length for strings, ignoring SMCL tags***From:*"Austin Nichols" <austinnichols@gmail.com>

**RE: st: Length for strings, ignoring SMCL tags***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**References**:**st: Length for strings, ignoring SMCL tags***From:*"Brian Karfunkel" <bkarfunkel@gmail.com>

**Re: st: Length for strings, ignoring SMCL tags***From:*"Austin Nichols" <austinnichols@gmail.com>

**RE: st: Length for strings, ignoring SMCL tags***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**Re: st: ranking with weights** - Next by Date:
**RE: st: Length for strings, ignoring SMCL tags** - Previous by thread:
**RE: st: Length for strings, ignoring SMCL tags** - Next by thread:
**RE: st: Length for strings, ignoring SMCL tags** - Index(es):

© Copyright 1996–2016 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |