I want to compare two Strings either they contain similar characters to print the number of common characters
Asked
Active
Viewed 890 times
2 Answers
1
To find out the common characters between two strings you can use the below method,
void findCommonCharacters(){
var str="geeksforgeeks";
var str2="platformforgeeks";
Set<String> uniqueList={};
for(int i=0;i<str.length;i++){
if(str2.contains(str[i])){
uniqueList.add(str[i]);
print("val : ${str[i]}");
}
}
}
This will give you the common characters between the two strings.
Also, to match characters of one String with another you can use default methods of String like contains(), startswith() and endswith() method.

Jay Mungara
- 6,663
- 2
- 27
- 49
0
If you want to match strings have a look at the Levenshtein Distance:
What are some algorithms for comparing how similar two strings are?

julian.a
- 1,163
- 2
- 9
- 21