Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Linq;
- class Program
- {
- public static void Main(string[] args)
- {
- // string longestStr = "123gt323";
- // string shortestStr = "23";
- string longestStr = "234d56";
- string shortestStr = "345";
- if (longestStr.Length < shortestStr.Length)
- {
- string temp;
- temp = longestStr;
- longestStr = shortestStr;
- shortestStr = temp;
- }
- Console.WriteLine("Longest " + longestStr);
- Console.WriteLine("Shortest " + shortestStr);
- if (longestStr.Contains(shortestStr))
- {
- int counter = 0;
- int index = longestStr.IndexOf(shortestStr);
- while (index != -1)
- {
- counter++;
- index = longestStr.IndexOf(shortestStr, index + 1);
- }
- StringBuilder sb = new StringBuilder();
- sb.Insert(0, shortestStr, counter)
- .Append(longestStr.Replace(shortestStr, string.Empty));
- Console.WriteLine(sb);
- }
- else
- {
- string wordOnlySearchCharacters = "";
- string wordWithoutSearchCharacters = "";
- for (int i = 0; i < longestStr.Length; i++)
- {
- if (shortestStr.Contains(longestStr[i]))
- {
- wordOnlySearchCharacters += longestStr[i];
- }
- else
- {
- wordWithoutSearchCharacters += longestStr[i];
- }
- }
- Console.WriteLine(wordOnlySearchCharacters + wordWithoutSearchCharacters);
- }
- Console.ReadKey(true);
- }
- }
Add Comment
Please, Sign In to add comment