KBD

Keith Devens .com

Wednesday, October 15, 2008 Flag waving
"Let me get this straight. He met with terrorists? Oh, that's good." – John Edwards (on finding out John Kerry's own diary testified to him meeting with North Vietnamese terrorists in Paris)
← A View from the Eye of the StormIraq a sovereign state! →

Daily link icon Saturday, June 26, 2004

Quickest way to find the length of a string?

Anyone have a secret way they use to quickly find the length of a string? Say you have a web form that only takes n characters, and you want to be a jerk and use up the whole thing exactly. Or, maybe you have a db field of a certain length and you want to measure what kind of stuff fits in it.

Here's what I do. I open up EditPlus, hit ctrl+shift+n for a new HTML document, type:

<script>
document.write("foo".length)
</script>

between the <body> tags, and hit ctrl+b to open up EditPlus's internal browser so I can see it.

(Yes, I know just having <script> is invalid, but it doesn't matter for this)

← A View from the Eye of the StormIraq a sovereign state! →

Comments XML gif

Phil Ringnalda (http://philringnalda.com) wrote:

How about this: Ctrl-T to open a new tab, then javascript:"foo".length{return}.

∴ Phil Ringnalda | 26-Jun-2004 11:40pm est | http://philringnalda.com | #4873

Keith (http://keithdevens.com/) wrote:

Phil, that's awesome. Thanks!

Keith | 27-Jun-2004 12:20am est | http://keithdevens.com/ | #4874

Jonas Galvez (http://jonasgalvez.com/blog) wrote:

python -c 'print(len("foo"))'

∴ Jonas Galvez | 27-Jun-2004 1:58am est | http://jonasgalvez.com/blog | #4876

Keith (http://keithdevens.com/) wrote:

That Python command line snippet didn't work for me. I'm not sure why... it's probably because I use Windows.

Keith | 27-Jun-2004 10:59pm est | http://keithdevens.com/ | #4877

Alan Green (http://cardboard.nu) wrote:

All the editors I use tell me the cursor position, so I move the cursor to the start of the string, look at the position counter, then move the cursor to the end of the string, and look at the position counter again.

∴ Alan Green | 28-Jun-2004 7:04pm est | http://cardboard.nu | #4882

Chris (http://today.icantfocus.com/blog/) wrote:

Along the lines of Alans suggestion. In my editor (Textpad), I just highlight the text. The status bar in the app tells me the selected texts character count.

∴ Chris | 28-Jun-2004 9:33pm est | http://today.icantfocus.com/blog/ | #4883

Feel free to post a comment below. Please see my comment policy.

Formatting Rules (No HTML):

  • **bold**, *italic*, _underlined_, --strikeout--
  • "text"="url" creates a link, and URLs are auto-highlighted
  • Blockquote: Like e-mail, begin paragraph with > (greater-than sign)
  • Lists: begin paragraph with *,-, or + (unordered), or # (ordered)
  • Code block: ?!code:language=perl|php|sql|javascript|etc.{\n}...{\n}?!/code

:
(will be your IP address if blank)
: (optional)
(Will not be shown on site)

: (optional)
:

October 2008
SunMonTueWedThuFriSat
 1234
567891011
12131415161718
19202122232425
262728293031 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 4 posts

Recent comments XML

new⇒Girls, please don't get breast implants

you people implants are fine these​days but they are like body organs​not e...

kym: Oct 15, 5:25pm

Spider solitaire

I have now won, at the "Difficult"​level, 186 games of Spider​Solitaire.  I...

75.179.28.113: Oct 13, 9:34am

I hate PHP

Elliot Anderson,

Dude!! You the​man! The reverse replacement for​array_u...

Alex Ndungu: Oct 11, 1:35am

Generated in about 0.301s.

(Used 8 db queries)

mobile phone