• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

another simple Java question: string search

HardTech

Golden Member
Say I have two strings that say "American Dollars" and "Australian Dollars"

I make another string that says "Dollar"... is there a way I can compare "Dollar" to the two strings above and have it return a true?

is there a partial match method in the String class?
 
hmm.. it's not working

so let's say:

String USD = "American Dollars";
String AUD = "Australian Dollars";
String HardTech = "Dollars";

HardTech.indexOf(USD) would return a value >= 1?
 
Originally posted by: HardTech
hmm.. it's not working

so let's say:

String USD = "American Dollars";
String AUD = "Australian Dollars";
String HardTech = "Dollars";

HardTech.indexOf(USD) would return a value >= 1?

you want: USD.indexOf(HardTech);
 
Originally posted by: HardTech
hmm.. it's not working

so let's say:

String USD = "American Dollars";
String AUD = "Australian Dollars";
String HardTech = "Dollars";

HardTech.indexOf(USD) would return a value >= 1?

No, but USD.indexOf(HardTech) should. Read the documentation for that method again.
 
You can also say

USA.endsWith(HardTech)

Which would return a boolean value of true.

P.S don't name local variables starting with a capital letter, it's breaks the conventional approach which would be hardTech.
 
Back
Top