need help for string
i face a problem where i wan compare the contain of the string, let say
string a = "java is cool";
string b = "well java is cool";
the tokens for a =3 n b=4,
i wan compare the whole line using tokenizer, where the b have the similar string on a.
the result will be,
token 2 3 4 from b is simalar with a
i also very blur wat i'm saying...hopefully u can understand...thx
Why not just tokenize (or better, split) and then compare from the right? How hard is that?Harder than typing intelligible English sentences, I will grant you, but...Drake
i'm not want to find the substrings..
i just wan to prove string b having the same content from string a...
where string a is the original sentence, and string b is copy from a..
the result will be...display out which letter is copy from string a...
well i think using other method such as
if i use 2 LOOP, compare token by token ....
Like This :
A1 compare to B1, A1 == B2, A1 == B3?
A2 == B1, A2 == B2, A3 == B3 ......
then izit whether we need using a matrix 2 do it?
> i face a problem where i wan compare the contain of
> the string, let say
>
> string a = "java is cool";
> string b = "well java is cool";
>
> the tokens for a =3 n b=4,
>
> i wan compare the whole line using tokenizer, where
> the b have the similar string on a.
>
> the result will be,
>
> token 2 3 4 from b is simalar with a
>
Presumably order is not an issue.
You want to do words?
- Use the java docs and look at String.split()
- Then compare the two arrays.
> any place can see the String.split() fucntion arr?
> my java book dun have...
>
> thx guys
If you mean to type this: "Is there any place where I can see an example of the String.split() method? My Java book doesn't have one." then here's an example:
/*
Check the API doc:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html
*/
public class Test {
public static void main(String[] args) {
String str = "java is cool";
String[] array = str.split(" ");
for(int i = 0; i < array.length; i++) {
System.out.println("array["+i+"] --> "+array[i]);
}
}
}