473,385 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help - Parsing

I want to be able to take
What is the Capital of California?/Sacramento/Redding/Georgia/Iran/A
from a text file and seperate it into seperate strings between the /

so it would have like

String question = "What is the Capital of California?
String answer1 = "Sacramento"
etc

I know i need to parse it with / as the delimiter but have no clue on how to do it and have searched on this forum with no avail.
Oct 17 '08 #1
5 1308
JosAH
11,448 Expert 8TB
Use the String.split() method; it returns an array with the separate components.
For details read the API documentation.

kind regards,

Jos
Oct 17 '08 #2
Nepomuk
3,112 Expert 2GB
Use the String.split() method; it returns an array with the separate components.
For details read the API documentation.

kind regards,

Jos
Wow, Jos not suggesting Regular expressions, where they could be used? ^^

Just kidding, String.split() is the easiest way to go here.

Greetings,
Nepomuk
Oct 21 '08 #3
Laharl
849 Expert 512MB
To quote Larry Wall, "Sometimes a programmer has a problem, so he decides to use regular expressions to solve that problem. Now he has two problems."

Regex is not always the answer, even in Perl.
Oct 21 '08 #4
Ganon11
3,652 Expert 2GB
To quote Larry Wall, "Sometimes a programmer has a problem, so he decides to use regular expressions to solve that problem. Now he has two problems."

Regex is not always the answer, even in Perl.
I take offense to that, sir. Regular expressions are ALWAYS the answer:

Expand|Select|Wrap|Line Numbers
  1. my @list = split //, $really_long_string; // Whee, using Perl to make a C-string.
  2. if ($big_word =~ /r/) {
  3.    print "\$big_word has an 'r' in it - yes it does!  It most certainly does!\n";
  4. }
  5. if ($a_string =~ /^q$/) {
  6.    print "\$a_string IS 'q'!  Why bother using the eq operator!?\n";
  7. }
All VERY, VERY useful applications of regexps.

(please add more emphasis to the VERYs at your discretion)
Oct 21 '08 #5
r035198x
13,262 8TB
I just thought I might add that the String.split method uses a regular expression to do the split.
Oct 21 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
0
by: burn_hall | last post by:
Hi, I have a problem and can't figure it out and need your help, please look at the following code and the output also a xml file snippet is down there too. Looking at the output I don't know why...
16
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
3
by: uestebanez | last post by:
Hi everybody! I have a little problem working with libxml SAX API. The problem is that I don't know how to stop parsing when I have processed the data I need. I don't want to parse all file, I...
4
by: ralphNOSPAM | last post by:
Is there a function or otherwise some way to pull out the target text within an XML tag? For example, in the XML tag below, I want to pull out 'CALIFORNIA'. ...
8
by: mrwoopey | last post by:
Hi, I need to get data from a client via a HL7 interface. How can I do this? Can I do this via visual basic? Please post, code, links, anything! Your help is appreciated! Phin
1
by: syhzaidi | last post by:
How can we do Parsing of Hexdecimel in C# reading string from stream file for eg.. i have a file like.......... 0f 2f 12 2d 3a.......in hexa decimal save in a file.txt and i m reading it from...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
2
by: embz | last post by:
this post concerns three pages. 1. this page: http://www.katherine-designs.com/sendemail.php i get the following errors: a lot of it seems to deal with the PHP code i inserted to the page....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.