• Post Reply Bookmark Topic Watch Topic
  • New Topic

i need help. [segmented text]  RSS feed

 
john can
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i need some help, please. lets say.. the sourcecodes 1) in java 2) in c [if possible ] i need help on- how-tos coding of segmentation of a few strings from a text file.

eg. in text.txt, i have a chained strings such as .. john,baba, crab, mouse, house.

i wana print it out as follows, where a new line is displayed if found a ",".

from file will be .. john,baba crab, mouse, house
output : -->
john
baba
crab
mouse
house

thanks for kindness.. john
 
slade cox
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You say to replace commas with newlines, but your example list split "baba crap" into two lines. Assuming this was a typo and you left out the comma, here is example code:



If you want it to split on any white space or a comma replace the regular expression in split() with this: "\\s*[\\s,]\\s*"
[ July 21, 2004: Message edited by: slade cox ]
 
john can
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks slade cox .. your code really works

but i need another help.

let's say, a row has 5 items, with commas, sch like --> [looks in tht txt file]

a,b,c,d,e
f,g,h,i,j

then i wana seperate them, like what u have coded, but 1 item in an array
so, it'll goes into database like;

*|1|2|3|4|5|
1|a|b|c|d|e|
2|f|g|h|i|j|

i have tested to use array, and the loop.. but i cant find a way to cast
helppp!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!