• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

split string matching '|' but not '\|'

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello!
somebody please help me...it is very very urgent.
i wanna split an argument string into array of string as follows:eg:
1) "abc|def|gh\|ij\\kl\m" would split into"abc", "def", "gh|ij\klm"
I did the first part '|'..i tried following way...but could not succeed..please suggest what shall i do not to match '\|' but match just this '|' to create a pattern.
i did this way
Pattern p = Pattern.compile("[\\| && [^\\\\| ] ]")
spltStrgs = p.split(arg, 0) ;
but still not getting what i wanted as mentioned above.
to say clearly..it is
If you want a "|" character to appear within an output string and not be interpreted as a splitting character, then it must be preceded by the escape character "\". Any character followed by the "\" character will be interpreted literally, and not treated as a special character. In this case, the "\" escape character is thrown away, and the character following it is appended literally to the current output string. So for example, "a|b" would be split as "a", "b" but "a\|b" would not be split and would appear in the output as a single string "a|b".
please answer ASAP...deadline...tomorrow...appreciates the intellectual who helps
basetti
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
basetti,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic