Results 1 to 13 of 13

Thread: String

  1. #1
    Join Date
    Apr 2010
    Posts
    19
    Rep Power
    0

    Unhappy String

    Hi all,

    i have a problem in string manipulation.
    i want to cut the part of the string for example

    ramesh(1001)
    i want to cut the number 1001
    how to do this. please help me on this.....

  2. #2
    hannes is offline Member
    Join Date
    Nov 2009
    Posts
    54
    Rep Power
    0

    Default

    You are not very clear in what you actually want to do, give some more information about the string and what you want to cut from it.

    Hannes

  3. #3
    Join Date
    Apr 2010
    Posts
    19
    Rep Power
    0

    Default String

    hi,

    "ramesh(1001)" is the string and i want to cut only "1001" from it.
    i hope this is clear to u

    regards,
    harsha

  4. #4
    hannes is offline Member
    Join Date
    Nov 2009
    Posts
    54
    Rep Power
    0

    Default

    In the java.lang.String class there is a method substring( int beginIndex, int endIndex ). You can use this method for your string :String myString = "ramesh(1001)".substring( 7, 11).

    Then the String myString contains "1001"

    Hope this helps,

    Hannes

  5. #5
    Join Date
    Apr 2010
    Posts
    19
    Rep Power
    0

    Default String

    hi,

    but i am reading the string from another page. so the string value changes every time.

    regards
    shreeharsha

  6. #6
    hannes is offline Member
    Join Date
    Nov 2009
    Posts
    54
    Rep Power
    0

    Default

    You say that the string value changes every time, but is there always a substring "1001" present in the string?

    Hannes

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,541
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by harsha.udupa2008 View Post
    hi,

    but i am reading the string from another page. so the string value changes every time.

    regards
    shreeharsha
    You can use regular expressions:

    Java Code:
    String yourNewString= yourString.replaceAll("\\d+", "");
    // result will be: "ramesh()"
    kind regards,

    Jos

  8. #8
    Join Date
    Apr 2010
    Posts
    19
    Rep Power
    0

    Default String

    hi,
    i want only the part within the bracket that is the substring 1001. the string changes whenever i read from another page.

    regards,
    harsha

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,541
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by harsha.udupa2008 View Post
    i want only the part within the bracket that is the substring 1001. the string changes whenever i read from another page.
    That's easy too:

    Java Code:
    String yourNewString= yourString.replaceAll("[^\\d]+", "");
    // result will be: "1001"
    kind regards,

    Jos

  10. #10
    Join Date
    Apr 2010
    Posts
    19
    Rep Power
    0

    Default String

    Hi,

    thank you very much. its working. can u just brief me how it works.

    regards,
    harsha

  11. #11
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,541
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by harsha.udupa2008 View Post
    Hi,

    thank you very much. its working. can u just brief me how it works.

    regards,
    harsha
    The regular expression matches one or more non-digits; they are replaced by exactly nothing "". Read the API documentation of the Pattern class for a short introduction to regular expressions.

    kind regards,

    Jos

  12. #12
    Join Date
    Apr 2010
    Posts
    19
    Rep Power
    0

    Default String

    Hi,

    where can i get the API Documentation. please suggest me.

    regards,
    harsha

  13. #13
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,541
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by harsha.udupa2008 View Post
    Hi,

    where can i get the API Documentation. please suggest me.
    Here it is; you're not telling me that until now you have been programming in Java without this documentation are you?

    kind regards,

    Jos

Similar Threads

  1. Replies: 7
    Last Post: 11-03-2009, 02:18 AM
  2. combine string[] into string like perl's join function
    By tekberg in forum Advanced Java
    Replies: 9
    Last Post: 02-23-2009, 01:05 PM
  3. Replies: 5
    Last Post: 01-11-2009, 10:12 AM
  4. Replies: 0
    Last Post: 11-20-2007, 04:59 PM
  5. Replies: 1
    Last Post: 08-03-2007, 10:52 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
  •