Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: Split string using its location

  1. #1
    parryowd is offline Member
    Join Date
    Feb 2012
    Posts
    1
    Rep Power
    0

    Default Split string using its location

    Hi all, I'm quiet new to Java programming, have done a few programs myself. Have a beginers book, and been trying some sample programs in that. But came up with one, that I was wondering how to do a part.

    Basically, the program will take an input from the user, that is a string, that in itself includes a workers name, the amount of hours they worked in a given week, and their wage rate. The program, then has to output its pay before taxes and all. This is what the initial string would be like.

    Sting numbers 0 - 19 Employees name
    20 - 21 Number of hours worked
    22 - 25 Hourly rate (Pound and pence)

    So an example would be

    JohnWaters---------12950

    So, the name is John Waters, works 12 hours in the week, and his rate is 9.50 per hour.

    I put - in instead of a space just for convienience for people to see clearer.

    What I was wondering was is there anyway to take that string, and split it into 3 substrings. I know you can split it, with some deliminater. But can you split a string, based on the amount of characters, if that makes sense.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Split string using its location

    Why not just use String's substring(...) method?
    Last edited by Fubarable; 02-05-2012 at 08:21 PM. Reason: corrected capitalization

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Split string using its location

    can you split a string, based on the amount of characters
    If you know the indexes, what's wrong with using substring(...) ?

    db

    edit Grrr...
    Fubarable likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Split a String with split()--Help
    By danilson in forum New To Java
    Replies: 7
    Last Post: 11-19-2010, 04:08 PM
  2. Split string help
    By Ben1 in forum New To Java
    Replies: 1
    Last Post: 11-08-2010, 04:28 PM
  3. String split
    By soccer_kid_6 in forum New To Java
    Replies: 3
    Last Post: 10-29-2010, 07:51 PM
  4. How to split a String using split function
    By Java Tip in forum java.lang
    Replies: 4
    Last Post: 04-17-2009, 08:27 PM
  5. How to split a String using split function
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 10-04-2007, 09:32 PM

Posting Permissions

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