Results 1 to 15 of 15
Like Tree4Likes
  • 1 Post By KevinWorkman
  • 1 Post By Dark
  • 1 Post By KevinWorkman
  • 1 Post By Norm

Thread: How to remove comma before an String?

  1. #1
    bhba73 is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default How to remove comma before an String?

    How to remove comma before an String?
    mySrting = bhanu,balaji,guddanti
    i want output = bhanu,balaji guddanti

    I'm new to java ..any suggestions will be appreciated in advance..

    Thanks
    Bhanu

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default

    Have you checked the String API for useful methods?
    Dark likes this.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    fakepics500 is offline Member
    Join Date
    Jul 2011
    Posts
    43
    Rep Power
    0

    Default

    use spilt function

  4. #4
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    The split function will turn that string into three strings. "bhanu" , "balaji" , "guddanti"
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  5. #5
    RichersooN is offline Senior Member
    Join Date
    Jan 2011
    Location
    Rizal Province, Philippiines
    Posts
    167
    Rep Power
    0

    Default

    Gentlemen, I think String.replace() can be useful to him?

  6. #6
    bhba73 is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default

    myString = bhanu,balaji,Guddanti
    i need my output will be = bhanu,balaji Guddanti

  7. #7
    bhba73 is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default

    i'm using jdk1.4 & pl/sql..actual output what i'm getting is select name,sno,sname,from stable
    what i wnt is select name,sno,sname from stable
    myString = name,sno,sname,from stable
    i want my output like below
    newString = name,sno,sname from stable(want to remove comma before from)

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default

    What determines which comma is to be removed?
    Is it always the last comma?
    Have you read the API doc for the String class? There are methods that will find the location of Strings and methods that will get parts of a String.
    Find the location of the last comma, get the String before it and the String after it and concatenate them

  9. #9
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default

    What Norm said.

    And to the other guys trying to "help", you'd be much better off pointing the OP to the API than offering incorrect solutions. Spoonfeeding is not helping, and usually it's wrong anyway.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  10. #10
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    @KevinWorkman, I agree. The OP doesn't want to browse the API, otherwise the OP would have completed the project by now. He wants to be spoon fed, which is why I offered no advice.
    KevinWorkman likes this.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  11. #11
    Join Date
    Dec 2009
    Location
    delhi india
    Posts
    3
    Rep Power
    0

    Default

    int index = s.lastIndexOf(",");
    System.out.println(s.substring(0, index) + " " + s.substring(index + 1));

  12. #12
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default

    Wow. We're really impressed. What about spoonfeeding not being helpful?
    Dark likes this.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  13. #13
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    I wish there was a face palm emoticon on this site. I bet it would be overused quite a bit however.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default

    What do you mean spoon, this looks like a shovel's full.

    The OP was very patient. Waiting long enough he didn't have to think or work at solving the problem (and maybe learn something), there was a show-off that came along and did his work for him
    Dark likes this.

  15. #15
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Quote Originally Posted by Norm View Post
    What do you mean spoon, this looks like a shovel's full.

    The OP was very patient. Waiting long enough he didn't have to think or work at solving the problem (and maybe learn something), there was a show-off that came along and did his work for him
    Maybe two shovels
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

Similar Threads

  1. How do I remove a substring from a string?
    By Unnel in forum New To Java
    Replies: 16
    Last Post: 07-11-2011, 11:56 AM
  2. Split string and remove
    By drogba123 in forum New To Java
    Replies: 2
    Last Post: 03-20-2011, 10:52 AM
  3. Remove comma
    By phantom06 in forum New To Java
    Replies: 2
    Last Post: 02-04-2011, 07:58 PM
  4. remove duplicate word in the string
    By katturv in forum New To Java
    Replies: 7
    Last Post: 12-19-2010, 07:16 PM
  5. Replies: 1
    Last Post: 05-07-2008, 01:19 AM

Posting Permissions

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