473,772 Members | 2,244 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help - Parsing

2 New Member
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 1319
JosAH
11,448 Recognized Expert MVP
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 Recognized Expert Specialist
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 Recognized Expert Contributor
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 Recognized Expert Specialist
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 MVP
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
9445
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 $ Last-Modified: $Date: 2003/10/28 19:48:44 $ Author: A.M. Kuchling <amk@amk.ca> Status: Draft Type: Standards Track
0
1493
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 it's not according to the code. Following code is pretty much clear: When method starts execution <Pat> Node is passed it has childNodes Inside for-loop
16
2906
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 loaded into cache, the slideshow doesn't look very nice. I am not sure how/when to call the slideshow() function to make sure it starts after the preload has been completed.
6
4349
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 result in any way. Who can help me, I thank you very very much. list.cpp(main program) //-------------------------------------------------------------------------- - #pragma hdrstop #pragma argsused
3
1745
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 only need read until I reach certain part of the xml and then stop parsing. Does anybody know how to stop? Another question is, Is necessary free any memory when I am using SAX API? I only call to "xmlSAXUserParseFile" and then callbacks "call...
4
2659
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'. <txtNameUSState>CALIFORNIA</txtNameUSState>
8
11169
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
1647
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 the file....... now i have to convert this in decimal and save in an array.of integers.......i thought it can be achieved through parsing ..means 0f could be stored in array converted in decimal...but remmber i m reading from a file///////////////i...
13
4514
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 command set consisting of several single letter commands which take no arguments. A few additional single letter commands take arguments:
2
6359
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. as my PHP skills are close to nil, i'm wary about fiddling with it myself. =\ 2. now this page: http://www.katherine-designs.com/contact.php
0
9620
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10261
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10104
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.