Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Parsing of String

 
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to parse following String
ABCDH2001API:0000:1:1:3:2:AB:3:ABC:4:ABCD
to
ABCDH2001API
0000
1
1
3
2
AB
3
ABC
4
ABCD
without using array and StringTokenizer. Only with the use of substring or startwith or other routines of the string.
Plz help me out,
Thanks
Angela
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tokenizing is the only way to go, however if you insist on doing it yourself. . . .
Well you can use indexOf(String str, int pos);
If you look for the delimiter (in this case ":") starting at 0, using a variable for pos. Each time you get a hit output the characters from the last hit to this hit using a subString(StartingPoint, FoundPoint).
 
Angela Jessi
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a bunch Cindy,
Can explain me by an example?
Thanks again,
Angela
 
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These kind of questions really puzzle me.
What is preventing you from using StringTokenizer? If this is an exercise from a course which has this requirement then the course is very flawed - understanding and achieving competence with Java is mostly about getting to know the Standard APIs. Any exercise with such silly requirements is not teaching you anything useful.
If it is your own idea to linit the solution so drastically, please think again, you are wasting time which would be better spent understanding the regular way of doing things.
 
Angela Jessi
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Frank & all,
I agree with your solution. But we have limitation not to use StringTokenizer b'cos we don't want to use lot's of object in our projects of course.
I got the solution of my question without using String Tokenizer and array.

Thanks again,
angela
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still think this is a crazy approach to learning Java. I see so much Java software where most of it could be replaced by a few simple uses of Standard classes which a smaller, faster and less buggy. Any course which teaches you to ignore the provided classes and produce your own poor replacements is teaching you to be a bad programmer.
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what the course is all about, but it could be a good idea to teach people how to code and think logically. I am always amazed at the people we get for interviews who can't think thru a problem. By keeping them from using a parsing function, they will learn how to walk an array. (After 15 years doing this, I still walk off the end of an array every now and them.)
Bruce.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree that such things are useful to learn, but why not choose an example which isn't duplicating an existing API method. All this indicates to me is that whoever sets the course is eihther lazy and has just tweaked some examples from another language, or so inexperienced in the subject matter that they don't look at the APIs first.
 
What are your superhero powers? Go ahead and try them on this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!