Java

Moderators: zibadian
Number of threads: 7836
Number of posts: 18235

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Regular expressions Posted by dmann200 on 17 Jun 2008 at 2:41 PM
I am trying to split a string containing "filename.wav"

I tried the following

String[]stringArray = fileString.split(".")

and also

String[]stringArray = fileString.split("\.")

Somehow I can't get JAVA to split it on the "." symbol because it is a reserved character in regular exressions. I read the page on regular expressions and couldn't find a way for it to recognize this character. I even tried it in octal and hex format...

Help!!


Report
Re: Regular expressions Posted by zibadian on 17 Jun 2008 at 3:45 PM
: I am trying to split a string containing "filename.wav"
:
: I tried the following
:
: String[]stringArray = fileString.split(".")
:
: and also
:
: String[]stringArray = fileString.split("\.")
:
: Somehow I can't get JAVA to split it on the "." symbol because it is
: a reserved character in regular exressions. I read the page on
: regular expressions and couldn't find a way for it to recognize this
: character. I even tried it in octal and hex format...
:
: Help!!
:
:
:
I've had a similar problem, and solved it using the regex character-selection group: []. Example:
  split("[.]");
Report
Re: Regular expressions Posted by Jonathan on 18 Jun 2008 at 1:42 AM
: I tried the following
:
: String[]stringArray = fileString.split(".")
:
: and also
:
: String[]stringArray = fileString.split("\.")
Thing is, I think Java itself is getting the \ and saying "ah, but there's nothing to escape with a ., so I just leave a literal . there". What you need, is for the \ to be passed along to the regex engine, so try escaping that.

String[]stringArray = fileString.split("\\.")

Jonathan

###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.