Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Gene Wirchenko Newsgroups: comp.lang.javascript Subject: String Processing in JavaScript Date: Fri, 31 Aug 2012 15:56:27 -0700 Organization: A noiseless patient Spider Lines: 30 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Info: mx04.eternal-september.org; posting-host="c0a6a1dc41fc92eb7000e57afbd16211"; logging-data="26502"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18t+70xdANLE2LnvqC+qvrkY381Phv9oNM=" X-Newsreader: Forte Agent 4.2/32.1118 Cancel-Lock: sha1:+5i4DGQq1/5iu7s1M8tjcSvlEV0= Xref: csiph.com comp.lang.javascript:15644 Dear JavaScripters: I will be passing back long result strings to my Web pages. These strings have to be parsed into error codes and form field contents. What I am working with looks like ::\n The value is encodeURIComponent()ed. The way that I am doing it right now for the first two values on a line is to look for a colon (with String.indexOf(), grab what is in front of the colon, and then delete up to the colon from the string. (I then grab the indicated number of characters and decode for the field value and ensure the following character is "\n" and delete up to the "\n".) I have to delete because of how String.indexOf() works. It does not have a string start point. Am I better off: 1) doing what I am doing, 2) keeping track of where I am in the string and have each .indexOf() operate on a .substr() of the string, or 3) using some other function I know not of? (What?) I suppose that another way of doing it would be a regex, but they have poor error handling. I expect to make a lot of errors while working this all out, and I prefer to get good error messages rather than just a parse failure. Sincerely, Gene Wirchenko