|
-
Dec 21st, 2005, 02:39 PM
#1
Thread Starter
Frenzied Member
Strings and things...
Hi there,
I haven't visited the forums in quite some time!
How is everyone
Anywho, i've been taking a computer science course this semester and we've been doing java(no fancy ide's..just Textpad ...used to use bluejay)
We have done a few simple games, frogger, etc.. as well as a console app with arrays to sort some tax calculations.
We are currently working on a console app to take a textfile and give the user options to do 1-9 different things... the option i am on at the moment is a Trimming method (i was trying to come up with a simple way to search through the contents stored in a string 's' for different characters such as (! , ' " -) and remove them. Heres what i wrote up today and of course it doesn't work but i'm wondering if trying to get a stringbuffer to work is the right thing or not....or should i use arrays and substrings to accomplish this, i also need to remove whitespace from the strings.
here goes my messy code:
Code:
public static String StringTrimWord(String s)
{
String rand = ("");
StringBuffer StringStuff = new StringBuffer(s);
int mySearch = StringStuff.indexOf("!");
StringStuff.setCharAt(mySearch, rand);
return s;
}
of course i'm calling stringtrimword(s); in my main method before i do system.outprint. I believe i was receiving an error with this code at 'rand' during my setCharAt call.
That is just an example of the idea i had to accomplish this easily.
Thanks for any input you may have!
- Kevin
:::`DISCLAIMER`:::
Do NOT take anything i have posted to be truthful in any way, shape or form.
Thank You!
--------------------------------
"Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
"Finaly I can look as gay as I want..." - NoteMe
Languages: VB6, BASIC, Java, C#. C++
-
Dec 21st, 2005, 05:58 PM
#2
Re: Strings and things...
use:
Code:
StringStuff.insert(mySearch,rand);
instead of :
Code:
StringStuff.setCharAt(mySearch, rand);
By the way, there is a method in java.lang.String called trim(); it Returns a copy of the string, with leading and trailing whitespace omitted.
Last edited by ComputerJy; Dec 21st, 2005 at 06:03 PM.
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Dec 21st, 2005, 07:30 PM
#3
Thread Starter
Frenzied Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|