[4886] in java-interest

home help back first fref pref prev next nref lref last post

Re: Strings in JAVA

daemon@ATHENA.MIT.EDU (Jules Damji)
Wed Jan 17 15:38:31 1996

Date: Wed, 17 Jan 1996 11:09:44 -0800
From: Jules.Damji@corp.sun.com (Jules Damji)
To: Jonathan_Mark_Smith@CCMAIL.PRUSEC.COM
Cc: java-interest@java.Eng.Sun.COM

 
|>     a string = "1234567" and I would like to make a string "345" can this 
|>     be done?
|>     

Again the String class has methods where you can extract substrings.
  
|>     Also say that I have a string like "23|45" and I would like to split 
|>     it at the "|" and make two string "23" and "45" can this be done?
|>     
|>

You will have to use the StringTokenizer class to get "23" and "45" as
substring, where the "|" is the token seperator. For example.

for (StringTokenizer t = new StringTokenizer("23|45", "|");
	t.hasMoreToken()) {
		String tmp = t.nextToken()
		// do something with tmp
}

Jules

--
+   jules.damji@corp.sun.com http://verona.corp/ +
++  webmaster@javacontest.sun.com http://javacontest.sun.com ++
+++ Java(tm): Programming for the Internet +++ http://java.sun.com/ +++

-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post