• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

how to parse a string

 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
can any of you plz suggest me how to parse a string that is passed to a javascript method.

Note that there may be more than one delimiter present anywhere in the string.In the following example i have to strip off all the spl chars(like "$" & "{" and so on) and extract only the alphabets.

Ex :

i/p(string) : "${abcd}${efgh}"

o/p (String[]) : {"abcd","efgh"}


In java this is pretty straight as we have StringTokenizer class there.but javascript is not allowing any such classes.but still how to get the output?.plz suggest me the soln at the earliest.

Regards,
Priya.
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JavaScript 1.2 (ECMAScript v3) has String.replace() which takes a regular expression and a replacement string.

In your example you may be better off with String.split("$"), which is a crude string tokenizer (returns an array of Strings).

Jules
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
basic idea



or





Eric
[ August 05, 2004: Message edited by: Eric Pascarello ]
 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If u know how to use jsp and hava, better use String.split() and charAt() with isDigit() or isChar() methods.
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cannot use JSP and "hava" in a Javascript method.
 
Could you hold this puppy for a sec? I need to adjust this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic