Results 1 to 3 of 3

Thread: Strings and things...

  1. #1

    Thread Starter
    Frenzied Member ice_531's Avatar
    Join Date
    Aug 2002
    Location
    Sitting w/ Bob Status: -Next -To- Null- Friend: Philip
    Posts
    1,152

    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++

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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

  3. #3

    Thread Starter
    Frenzied Member ice_531's Avatar
    Join Date
    Aug 2002
    Location
    Sitting w/ Bob Status: -Next -To- Null- Friend: Philip
    Posts
    1,152

    Re: Strings and things...

    Thanks for the reply

    I guess i should have looked up stringbuffer on the sun site before posting

    Never saw insert lol

    Hopefully it will work though, i don't have my code on this pc so i can't test it right now unless i make a little sample project...but i can wait

    Anywho, this will be great if it does work - the methods my professor was recommending involved alot more code and dealing with arrays and subarrays being held in temp strings etc.... my code will be faster i think.

    Anymore suggestions would be nice; maybe a faster way? or something i don't know about..or any links to sites with some reading on strings and file i/o would be appreciated.

    -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++

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width