File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String " Watch "String " New topic
Author

String

abhinas raj
Ranch Hand

Joined: Jun 02, 2012
Posts: 47
String s1="john,24,usa"; How to extract each substring from the given string without using any built-in Java methods of either String or StringBuffer/StringBuilder class ? please help
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14150
    
  18

Without any of the methods in the String class it will be impossible, because there's no way to get at the contents of the string without calling any methods of the String class.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Ameya Kamat
Greenhorn

Joined: Mar 26, 2013
Posts: 1
could you be a little more clear about the question? what are the substrings you are trying to extract? is ',' a token if so you could use StringTokenizer. if the substrings are going to be a fixed length then you could create a inputreader object and read specific characters. I think it all comes down to what you define as substring
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
Welcome to the Ranch

If you read the StringTokenizer (←link) documentation, you find you ought not to use it.
Kenneth Van Gysegem
Ranch Hand

Joined: Mar 30, 2013
Posts: 33
Hi,
I think the best way to do this is with the method String.split().
This method allows you to split a String in different pieces, using a delimiter that determines where the String is split.
These pieces, then, will be put in an array.

For example:


the output will be:

This
is
a
test

I hope this helped
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
Welcome to the Ranch , Kenneth van Gysegem

I think the first post means that String#split is not permitted. It is a daft exercise like that, anyway.
Kenneth Van Gysegem
Ranch Hand

Joined: Mar 30, 2013
Posts: 33
Campbell Ritchie wrote:Welcome to the Ranch , Kenneth van Gysegem

I think the first post means that String#split is not permitted. It is a daft exercise like that, anyway.


You're right. String.split() is a built in java-method.
And you are right about the exercise being daft too
 
wood burning stoves
 
subject: String