Results 1 to 4 of 4
Thread: how to get next character/string
- 03-27-2009, 12:44 AM #1
Member
- Join Date
- Mar 2009
- Posts
- 48
- Rep Power
- 0
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..
- 03-27-2009, 03:22 AM #2
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); }
- 03-28-2009, 03:19 AM #3
Member
- Join Date
- Mar 2009
- Posts
- 48
- Rep Power
- 0
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'.
ouput :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);
but i want only one character(jocky, vicky, rocky....) after the target string.jocky
vicky sdkafjlkasdjflksadjflkasd
rocky dfjksd, lksdjf
pls help me...
-
Similar Threads
-
API for Character Recognition
By LankanSniper in forum Advanced JavaReplies: 5Last Post: 03-25-2009, 11:39 AM -
Read from a certain character to a certain character
By blackstormattack in forum New To JavaReplies: 0Last Post: 03-16-2009, 11:36 AM -
Inserting string with slash character into database
By Java Tip in forum Java TipReplies: 0Last Post: 02-07-2008, 08:57 AM -
reading text character by character
By bugger in forum New To JavaReplies: 2Last Post: 11-09-2007, 08:54 PM -
validate hex character
By paul in forum New To JavaReplies: 1Last Post: 07-25-2007, 09:08 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks