Results 1 to 7 of 7
Like Tree3Likes
  • 2 Post By JosAH
  • 1 Post By JosAH

Thread: String manipulation

  1. #1
    rackd1989 is offline Member
    Join Date
    Jul 2012
    Posts
    1
    Rep Power
    0

    Lightbulb String manipulation

    given a string like
    "2,up,1000,2,down,1300,3,up,1000"
    speed,direction,start point ..........
    we have to tokenize the string in such a way that 2,2,3 are in speed array/up,up,down are in direction array and 1000,1300,1000 are in st. pt array
    plz reply the code......waiting

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

    Default Re: String manipulation

    Quote Originally Posted by rackd1989 View Post
    plz reply the code......waiting
    So you're simply handing over your problem to us? Forums don't work that way; keep on waiting.

    Jos
    awinston and ManyProblems like this.
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: String manipulation

    A good start would be studying the String API: String (Java Platform SE 7 )
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  4. #4
    kire9dk is offline Member
    Join Date
    Sep 2009
    Posts
    15
    Rep Power
    0

    Default Re: String manipulation

    Quote Originally Posted by rackd1989 View Post
    given a string like
    "2,up,1000,2,down,1300,3,up,1000"
    speed,direction,start point ..........
    we have to tokenize the string in such a way that 2,2,3 are in speed array/up,up,down are in direction array and 1000,1300,1000 are in st. pt array
    plz reply the code......waiting
    You can use something called Pattern + Matcher,
    example
    Pattern wayPattern = Pattern.compile("(\\d+),(up|down)");
    LinkedList<String> wayList = new LinkedList<String>();
    Matcher wayMatcher =wayPattern.matcher("2,up,1000,2,down,1300,3,up,10 00");
    while(wayMatcher.matches()){
    wayList .add((wayMatcher.group(1)));
    }

    "(\\d+),(up|down)" is called regular expression. Here you are having 2 matching groups, (\\d+) - meaning one or more digiti, (up|down) - meaning up or down,
    read Pattern (Java Platform SE 7 )
    http://docs.oracle.com/javase/7/docs/api/java/util/regex/Matcher.html

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

    Default Re: String manipulation

    @kire9dk: while we do value your enthusiasm as a new memeber here, we don't spoonfeed posters; they should do some thinking for themselves; this particular poster simply handed over his/her problem to us and sat back, waiting for us to solve his/her problem. We don't do that here.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    kire9dk is offline Member
    Join Date
    Sep 2009
    Posts
    15
    Rep Power
    0

    Default Re: String manipulation

    Quote Originally Posted by JosAH View Post
    @kire9dk: while we do value your enthusiasm as a new memeber here, we don't spoonfeed posters; they should do some thinking for themselves; this particular poster simply handed over his/her problem to us and sat back, waiting for us to solve his/her problem. We don't do that here.

    kind regards,

    Jos
    I will have this in mind next time when I will replaying to some posts or asking a question.

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

    Default Re: String manipulation

    Quote Originally Posted by kire9dk View Post
    I will have this in mind next time when I will replaying to some posts or asking a question.
    Good, and welcome to the forums and have fun here; if you don't spoonfeed (or ask to be spoondfed) everbody is happy.

    kind regards,

    Jos
    DarrylBurke likes this.
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Help with String Manipulation
    By RossGoldenstein in forum New To Java
    Replies: 2
    Last Post: 09-28-2011, 04:24 AM
  2. String manipulation
    By lakshmibvaraprasad in forum New To Java
    Replies: 4
    Last Post: 07-16-2011, 01:41 PM
  3. String manipulation
    By i4ba1 in forum Advanced Java
    Replies: 2
    Last Post: 12-22-2010, 08:53 AM
  4. String Manipulation
    By tmotse in forum New To Java
    Replies: 1
    Last Post: 10-14-2010, 01:25 PM
  5. Help needed with string manipulation
    By stringkilla in forum New To Java
    Replies: 47
    Last Post: 09-07-2010, 03:25 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
  •