Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
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
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
Split String by $
Tusshar Fasate
Ranch Hand
Posts: 81
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
I am trying to split a
string
by $ ..but I am not getting desirable output.
here is my code..
public class TestQuery { public static void main(String[] args) throws Exception { System.out.println("Hello"); String str=" Fri Jul 16 16:01:23 IST 2010 $ sds"; String strArr[]=str.trim().split("//$"); for(int i=0;i<strArr.length;i++){ System.out.println("strArr:"+i+" element ->"+strArr[i]); } System.out.println("Run successfully.."); } }
output:
Hello
strArr:0 element ->Fri Jul 16 16:01:23 IST 2010 $ sds
Run successfully..
Please help me out on this.
Thanks..
Tusshar Fasate
Ranch Hand
Posts: 81
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
one small correction ..
String strArr[]=str.trim().split("$");
instread of this // String strArr[]=str.trim().split("//$");
please help me.
Martin Vanyavchich
Ranch Hand
Posts: 241
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Wrong slashes
try
public static void main(String[] args) throws Exception { System.out.println("Hello"); String str = " Fri Jul 16 16:01:23 IST 2010 $ sds"; String strArr[] = str.trim().split("\\$"); // note backslash here for (int i = 0; i < strArr.length; i++) { System.out.println("strArr:" + i + " element ->" + strArr[i]); } System.out.println("Run successfully.."); }
SCJP 6, OCMJD 6, OCPJWSD 6
I no good English.
Pramod P Deore
Ranch Hand
Posts: 633
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Try this one
public class TestQuery { String fullString,rec1,rec2,rec3,rec4; String[]arr; public static void main(String[] args) { TestQuery t = new TestQuery(); t.splitString(); } public void splitString() { fullString=" Fri Jul 16 16:01:23 IST 2010 $ sds$ another string $once more"; arr = fullString.split("\\$"); for (int i=0;i<arr.length;i++) { rec1 = arr[0]; rec2 = arr[1]; rec3 = arr[2]; rec4 = arr[3]; } System.out.println (rec1); System.out.println (rec2); System.out.println (rec3); System.out.println (rec4); } }
>
Life is easy because we write the source code.....
Tusshar Fasate
Ranch Hand
Posts: 81
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks a lot Pramod and Martin for your quick reply...
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Problem in parsing
problem with showing records in hibernate
Collections :List.add throws runtime Exception(Unsupported Exceptions)
read next byte
Why my program works fine when i write Thread.sleep(0)
More...