It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Java Forum

Java String::Compare

Java String::Compare

Postby gcardinal on Wed Apr 11, 2007 9:31 pm

Hello!

I'm working on text processing/analyze project and I really need a string compare function that will work not only tell if 2 strings are equal but will also show result is in percentage. If the strings are exactly equal, it would return 1, if they have nothing in common, it would return 0.

Something like this Perl script:
http://search.cpan.org/~druoso/String-C ... Compare.pm

Is there anything like it on Java?

Thank you
gcardinal
 
Posts: 0
Joined: Wed Apr 11, 2007 9:31 pm

it can be done

Postby ggomez on Tue Apr 17, 2007 5:40 am

yes it can be done with java

but not with any ultra method that i know

in the web page you posted, you have most of the logic work and
with patience you can do it your self in java just using the
methods of the String class and some other tricks.

good luck
ggomez
 
Posts: 45
Joined: Tue Apr 17, 2007 3:30 am
Location: !!!!!MéXiCo¡¡¡¡¡¡

Postby Stiks on Wed Apr 18, 2007 2:30 am

I might be thinking too basic, but can't you compare to strings by doing this?:

if(a.equalsTo(b))
{
System.out.println("1");
}

else
{
System.out.println("0");
}

The Sun site has a list of all the available classes and their methods.
Stiks
 
Posts: 7
Joined: Wed Apr 18, 2007 2:25 am

Yep

Postby ggomez on Wed Apr 18, 2007 2:38 am

thats right

The String class has most of the methods you need

if you need more sofisticate code maybe you will need to check the word
character by character.
ggomez
 
Posts: 45
Joined: Tue Apr 17, 2007 3:30 am
Location: !!!!!MéXiCo¡¡¡¡¡¡

Postby abdulaziz on Wed Aug 29, 2007 11:41 am

Yes it can be done.

String s ="abc";
String s1="xyz";

if(s.equals(s1)){
return 1;
}
else{
return 0;
}
abdulaziz
 
Posts: 0
Joined: Fri Jul 20, 2007 6:55 am

Postby nanair01 on Tue Sep 04, 2007 11:41 am

yea the above post exactly does the purpose.... or if u need more functions using Strings refer the following link
http://java.sun.com/j2se/1.4.2/docs/api ... tring.html
nanair01
 
Posts: 4
Joined: Tue Sep 04, 2007 11:31 am
Location: india


Who is online

Users browsing this forum: No registered users and 1 guest