Results 1 to 11 of 11
  1. #1
    velvetymold is offline Member
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Default Okay..I'm waiving the white flag on this

    So I'm new to Java and honestly I'm not even sure this is where I should post something like this but I was wondering if someone out there in Java-land can help me with a class project my teacher is wanting us to complete. I don't need anyone to do it for me but I just need some one to help out this poor sap.

    So there's this data like: Doe#John#1231231234#123
    Doe#Jane#4564564567#456
    And he wants it to look like:
    Name Telephone Number Code
    John Doe (123) 123-1234 123
    Jane Doe (456) 456-4567 456

    I know it's string manipulation, and I've got to throw in some substrings and replaces...but getting started is the problem.

    Can any good souls out there help out?

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

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

    Default

    Look at the String#split("#") method to split your Strings on the "#" String and then look at the System.out.printf(...) method for formatted printing.

  4. #4
    velvetymold is offline Member
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Default Still not there

    I have used substring before, but not in that context. Here is what I have so far which prints out a bunch of stuff...the professor is requesting we either use loops to count the #'s or the indexof() method (which I have never used). I'm trying to get it to loop, but I think (know) my loop is in the wrong place...and again the whole substring # thing is really throwing me off.

    If any of you guys/gals can help a noob out and point me in the right direction I would be forever in your debt!

    import java.util.Scanner;

    import java.io.File;

    import java.io.FileNotFoundException;

    public class cell

    {



    public static void main (String[]args)

    {

    int count, count0=0, count51=0, count101=0, wholeLength=0, i=0;

    String fname="", lname="", phone="", sms="", contacts="", name="", hold="";

    Scanner fileScan;

    try

    {



    fileScan=new Scanner (new File ("C:\\Documents\\contacts.txt"));

    System.out.println ("Name" + "\t"+ "\t"+"\t"+ "Phone Number" + "\t" + "\t" + "SMS");





    while (fileScan.hasNextLine()) {

    i=i=1;
    while (i<=4)
    {
    hold=fileScan.next();
    if (i==1)
    lname=hold;
    else
    if (i==2)
    fname=hold;
    else
    if (i==3)
    phone=hold;
    else
    sms=hold;
    i++;

    }




    System.out.println(fname + lname);

    }

    }catch (Exception e) {

    e.printStackTrace();

    }
    }
    }

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Fubar gave you some excellent advice. why did you ignore it? Have you been forbidden from using the split method?

  6. #6
    velvetymold is offline Member
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Default

    I didn't ignore it...I've just never used it.

    That's the problem...where I fit it in and what the code looks like.

  7. #7
    velvetymold is offline Member
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Default

    We haven't covered the split method...so I'm thinking my teacher would frown on using it, too.

  8. #8
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Quote Originally Posted by velvetymold View Post
    I've just never used it.
    So how are you supposed to learn how to use it? Try it and find out how it works.
    so I'm thinking my teacher would frown on using it, too.
    Your teacher frowns upon the students learning? How odd!

  9. #9
    velvetymold is offline Member
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Default

    Well he only wants us to use what we've learned which as been loops, strings..no arrays (yet). If we put something new in there we get points taken off. But it seems that the majority of the class is having a problem with this one and now we are allowed to use the index(of) method that we haven't studied yet (to throw another monkey wrench into it). So now I'm trying to learn about index(of) methods...I'm really tired.

  10. #10
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    OK since you are not allowed to use arrays and split method returns an array I guess it is out. Here's a little hint
    Java Code:
    String data = "Doe#John#1231231234#123";
    System.out.println(data.substring(0, data.indexOf("#")));

  11. #11
    velvetymold is offline Member
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Default

    Ooo! Okay! That helps! You're so awesome! Thank you so much!

Similar Threads

  1. JSTL and HTML White space
    By newakdev in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 02-24-2010, 06:54 PM
  2. javac: invalid flag: Files\Java\jdk1.6.0_18;C:\Program
    By darrell22 in forum New To Java
    Replies: 5
    Last Post: 02-09-2010, 09:27 AM
  3. How to display a String that contains more than one white spaces
    By thachun in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 09-27-2009, 10:16 AM
  4. BufferStrategy and white rows of pixels
    By TobyLobster in forum Java 2D
    Replies: 2
    Last Post: 12-29-2008, 02:49 PM
  5. White Space Issue
    By sibythoma1984 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 04-22-2008, 01:05 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
  •