473,386 Members | 1,779 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,386 software developers and data experts.

How do you read up to a specific character in a line of text?

I have a line of characters that need to be separated. One example is like this:

513413;dialog_513413;Sally Mae has some jobs for you.;

Three sets of data all split into three groups placed in one line. What I would like to do is be able to read each group up to the semicolon (obviously without including it when it becomes displayed or used in the program).

So in conclusion I would just like to know a method that can either count or read the string (from a file) up to the semicolon. I am aware of string.read(size), but obviously size is needed and it is variable. Highly prefer having size given also.

Thanks! :)
Sep 6 '10 #1

✓ answered by bvdet

String method split() was made for situations like this.
Expand|Select|Wrap|Line Numbers
  1. >>> line = "513413;dialog_513413;Sally Mae has some jobs for you.;"
  2. >>> line.split(";")[0]
  3. '513413'
  4. >>> for item in line.split(";"):
  5. ...     print item
  6. ...     
  7. 513413
  8. dialog_513413
  9. Sally Mae has some jobs for you.
  10.  
  11. >>> 

2 18217
bvdet
2,851 Expert Mod 2GB
String method split() was made for situations like this.
Expand|Select|Wrap|Line Numbers
  1. >>> line = "513413;dialog_513413;Sally Mae has some jobs for you.;"
  2. >>> line.split(";")[0]
  3. '513413'
  4. >>> for item in line.split(";"):
  5. ...     print item
  6. ...     
  7. 513413
  8. dialog_513413
  9. Sally Mae has some jobs for you.
  10.  
  11. >>> 
Sep 6 '10 #2
Thanks again bvdet! :]
Sep 7 '10 #3

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

Similar topics

1
by: David Thomas | last post by:
Hi there, a while ago, I posted a question regarding reading japanese text from a text file. Well, since I solved the problem, I thought I'd post my solution for the benefit of other people with...
2
by: Leif K-Brooks | last post by:
I'm trying to write a Brainfuck interpreter in Perl out of boredom and desire to improve my skills. I'm running into one prroblem, though: Brainfuck needs to read one character of input at a time,...
11
by: michael | last post by:
I have a group of links prefixed with the arrow as follows: »link1 »link2 »link3 I would like the arrows to be vertically aligned middle of the text, like as if they were bullets of list item,...
13
by: Dan V. | last post by:
How do I create a one line text file with these control codes? e.g.: 144 = 0x90 and 147 = 0x93? I am trying to create a one line text file with these characters all one one row with no spaces. ...
3
by: Jow Blow | last post by:
I am trying to make a word wrap type function for a multi line text box field that will be saved to a text file. The word wrap property looks good in the app but when saved to a text file the line...
35
by: RyanS09 | last post by:
Hello- I am trying to write a snippet which will open a text file with an integer on each line. I would like to read the last integer in the file. I am currently using: file = fopen("f.txt",...
8
by: MLH | last post by:
Am trying to import 20,000+ lines of text in a file FTP'd from a UNIX platform to windows via FTP session in a DOS box. About 2000 records have multiple lines in them separated by CRLF's. ...
2
by: JB | last post by:
I'm trying to read a text file, and store the position of a specified line, and then later seek back to that line and start reading again. I'm using simple code like the following: StreaReader...
6
by: rohit | last post by:
Hi All, I am new to C language.I want to read integers from a text file and want to do some operation in the main program.To be more specific I need to multiply each of these integers with another...
1
by: judo | last post by:
we have a project in our school. we are going to create C like compiler. Our group will go going to use vb.net to make it happen. But our problem, we don't know how to read a character one at a time...
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:
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...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
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...

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.