Skip to content

Instantly share code, notes, and snippets.

@Saifallak
Created August 7, 2019 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Saifallak/e4b6576ac992dd770bed161fbb200aae to your computer and use it in GitHub Desktop.
Save Saifallak/e4b6576ac992dd770bed161fbb200aae to your computer and use it in GitHub Desktop.
just a small code in dart that counting the identical characters and diff characters in two string;
import 'dart:convert';
import 'dart:io';
main() {
/// No. of Different Characters in the two Strings;
int diff = 0;
/// No. of Identical Characters in the two Strings;
int correct = 0;
/// Print Msg for User;
print("hi enter string 1");
/// Input Code
var line = stdin.readLineSync(encoding: Encoding.getByName('utf-8'));
/// Print Msg for User;
print("hi enter string 2");
/// Input Code
var line2 = stdin.readLineSync(encoding: Encoding.getByName('utf-8'));
/// Calculating the largest Length of the two strings to be Loop Length;
int loopLength = line.length > line2.length ? line.length : line2.length;
/// Looping on -
for (int i = 0; i < loopLength; i++) {
/// If string length <= i, then there is no string to check so counting++
if (line.length <= i || line2.length <= i) {
print("length <= $i");
diff++;
/// Stop executing the checks, we already know what we want;
continue;
}
/// Normal equal between characters if not equal counting++
if (line[i] != line2[i]) {
print("diff at $i [${line[i]},${line2[i]}]");
diff++;
/// Stop executing the checks, we already know what we want;
continue;
}
/// If all the checks are invalid then it's Identical Characters;
print("correct ${line[i]}");
correct++;
}
/// Printing Result;
print("diff $diff , correct $correct");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment