StringToInt :- Algrothim to convert number string into integer.
public static void StringToInt(string source)
{
string lookUpValue = "0123456789";
int total = 0;
foreach (char c in source)
{
if (lookUpValue.Contains(c))
{
total = (total * 10) + lookUpValue.IndexOf(c);
}
}
Console.WriteLine(total);
Anagram :- words are said to be Anagrams of each other if they share the same set of letters to form the respective words. Remember, it’s just rearranging the existing letter.
private static void StrAnagram(string str1, string str2)
{
//One way
if (str1.Length == str2.Length)
{
var char1 = str1.ToLower().ToCharArray();
var char2 = str2.ToLower().ToCharArray();
Array.Sort(char1);
Array.Sort(char2);
str1 = new string(char1);
str2 = new string(char2);
if(str1 == str2)
Console.WriteLine(true);
else
{
Console.WriteLine(false);
}
}
}
public static void StringToInt(string source)
{
string lookUpValue = "0123456789";
int total = 0;
foreach (char c in source)
{
if (lookUpValue.Contains(c))
{
total = (total * 10) + lookUpValue.IndexOf(c);
}
}
Console.WriteLine(total);
Anagram :- words are said to be Anagrams of each other if they share the same set of letters to form the respective words. Remember, it’s just rearranging the existing letter.
private static void StrAnagram(string str1, string str2)
{
//One way
if (str1.Length == str2.Length)
{
var char1 = str1.ToLower().ToCharArray();
var char2 = str2.ToLower().ToCharArray();
Array.Sort(char1);
Array.Sort(char2);
str1 = new string(char1);
str2 = new string(char2);
if(str1 == str2)
Console.WriteLine(true);
else
{
Console.WriteLine(false);
}
}
}
No comments:
Post a Comment