Results 1 to 4 of 4
  1. #1
    doha786 is offline Member
    Join Date
    Mar 2009
    Posts
    48
    Rep Power
    0

    Question how to get next character/string

    i m very new in java. now facing prob to get a string/character after a particular string. suppose from a text file where mentioned few friends name such as my first friend jacky, second frind vikcy and so on..... so here particular string will be 'friend' and need to get the immediate next character of the friend. anybody please help me to do this program...........pls pls..

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Pseudo code suggestion:
    Java Code:
    String target = "friend";
    String line = a_line_read_from_file
    if(line.indexOf(target) != -1) {
        //this line has the target string in it
        int index = line.indexOf(target) + target.length();
        if(index != -1)
            char nextChar = line.charAt(index);
    }

  3. #3
    doha786 is offline Member
    Join Date
    Mar 2009
    Posts
    48
    Rep Power
    0

    Default

    thank u so much for ur kind help..
    i almost solve my prob but right now its showing rest of the words after my target string 'friend'.
    FileReader fr;
    BufferedReader br;
    String append="";
    String word= new String();
    int x;
    String target = "friend";


    try {
    fr = new FileReader ("C:/Users/user/Desktop/java/test.txt");
    br = new BufferedReader(fr);

    while ((append = br.readLine()) != null) {
    x = append.toLowerCase().indexOf(target);
    if (x>=0) {
    word=append.substring(append.indexOf(target)+6);

    System.out.println (word);
    ouput :
    jocky
    vicky sdkafjlkasdjflksadjflkasd
    rocky dfjksd, lksdjf
    but i want only one character(jocky, vicky, rocky....) after the target string.
    pls help me...

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

    Default

    Perhaps you want to use the method suggested above, charAt(...)?

Similar Threads

  1. API for Character Recognition
    By LankanSniper in forum Advanced Java
    Replies: 5
    Last Post: 03-25-2009, 12:39 PM
  2. Read from a certain character to a certain character
    By blackstormattack in forum New To Java
    Replies: 0
    Last Post: 03-16-2009, 12:36 PM
  3. Replies: 0
    Last Post: 02-07-2008, 09:57 AM
  4. reading text character by character
    By bugger in forum New To Java
    Replies: 2
    Last Post: 11-09-2007, 09:54 PM
  5. validate hex character
    By paul in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 10:08 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
  •