LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-10-2004, 02:07 AM   #1
jbstew32
Member
 
Registered: Feb 2003
Location: Atlanta, GA
Posts: 151

Rep: Reputation: 15
Java Strings


Let's hypothetically say you have a simple string, ie "The.Dog.Ran."
and you ONLY want to get rid of the LAST period without altering the others. How would you do that easily? Preferably without the use of arrays. So basically the end result would be to display "The.Dog.Ran"
 
Old 02-10-2004, 04:40 AM   #2
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
Sure thing mate. You've to use .length() which returns the size of a string and .substring(start, stop) to read a string from the beginning till the end. Here is a working example:

Code:
public class Testing{
	public static void main (String[] arguments){
		String ie = "The.Dog.Ran.";

		System.out.println(ie.substring(0, ie.length()-1));
	}
}
Regards!
 
Old 02-10-2004, 04:44 AM   #3
jbstew32
Member
 
Registered: Feb 2003
Location: Atlanta, GA
Posts: 151

Original Poster
Rep: Reputation: 15
thanks
 
Old 02-15-2004, 12:08 PM   #4
german
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Debian etch, Gentoo
Posts: 312

Rep: Reputation: 30
String s = "The.dog.ran."
int idx = s.lastIndexOf(".");
String result = s.substring(0,idx); // this is now "The.dog.ran"

HTH

B.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to find duplicate strings in vertical column of strings markhod Programming 7 11-02-2005 04:04 AM
strings in c djgerbavore Programming 8 01-11-2005 04:27 PM
Java printing - problem with large strings Andy@DP Programming 2 08-03-2004 02:23 PM
Strings and int? kalleanka Programming 12 02-10-2004 04:34 AM
align columns of strings and explain '\t' (java) dave bean Programming 3 01-10-2004 10:55 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration