<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Lotushints &#187; string traversing</title>
	<atom:link href="http://www.lotushints.com/tag/string-traversing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lotushints.com</link>
	<description>Lotus Notes tips &#38; tricks you always hoped you will not need</description>
	<lastBuildDate>Thu, 29 Dec 2011 09:47:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Javascript string traversing</title>
		<link>http://www.lotushints.com/2010/06/javascript-string-traversing/</link>
		<comments>http://www.lotushints.com/2010/06/javascript-string-traversing/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 06:00:07 +0000</pubDate>
		<dc:creator>Vladimir Kocjancic</dc:creator>
				<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[string traversing]]></category>

		<guid isPermaLink="false">http://www.lotushints.com/?p=507</guid>
		<description><![CDATA[Lately I needed to parse format that Cisco uses for specifying transfer masks and route patterns to an array of telephone numbers a user could choose from. I wrote a neat javascript function that traverses the string and does what needed. I even wrote a neat recursive function that displayed the numbers in HTML select [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I needed to parse format that Cisco uses for specifying transfer masks and route patterns to an array of telephone numbers a user could choose from. I wrote a neat javascript function that traverses the string and does what needed. I even wrote a neat recursive function that displayed the numbers in HTML select field.<br />
<span id="more-507"></span><br />
All worked fine. Until someone decided to test the thing on VM running Windows XP SP3 with IE 8.0.6001.18702 . The thing crashed. Not only that, it also displayed a nice little pop-up claiming that Javascript is running slow. We all know that really means you have an infinite loop somewhere in JS code. Thing is, I ran the code numerous times on my PC, which runs Windows XP SP3 and IE 8.0.6001.18702 as well. The only difference that my PC is not  a virtual machine. And it worked without a glitch. So I tested it to death in VMs IE and eventually located the problem.</p>
<p>Remember how you traversed a string in C? Typically you wrote something like this (and yes, I know I probably should have used a pointer):</p>
<pre>
char pszString[100] = "My silly string\0";
for (int i=0; i&lt;strlen(pszString); i++) {
   char ch = pszString[i];
   //do something spiffy
}
</pre>
<p>As far as I remember, I use that all the time in JavaScript as well. I never had any issues. Guess what? In IE on VM that was the cause of my problems. So, all I had to do was:</p>
<pre>
var pszString = new String("My silly string");
for (int i=0; i&lt;strlen(pszString); i++) {
   char ch = pszString.substr(i, 1);
   //do something spiffy
}
</pre>
<p>And the stuff magically started to work.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lotushints.com/2010/06/javascript-string-traversing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

