Answer the question
In order to leave comments, you need to log in
Working with arrays (list) and characters -2-?
There is an array:
List<string> text = ["89192864554","+7926?874?22?44", "[email protected]" , "vk.com", "youtube"];
string phone = "+7920?855?43?55 89192864554";
string site = "vk.com";
string email = "[email protected]";
Answer the question
In order to leave comments, you need to log in
Let me explain in advance that the ParseToString method takes List as arguments, and returns a string in which exactly the elements of this array (list) are written. Regulars for your task can not be used.
class Program
{
public static string ParseToString(List<string> t)
{
string _return = "";
for(int i=0;i<t.Count;i++)
{
if (i == t.Count-1)
{
_return += t[i];
break;
}
_return += t[i] + " ";
}
return _return;
}
public static void Main(string[] args)
{
List<string> text = new List<string>(new String[]{"89192864554","+7926?874?22?44", "[email protected]" , "vk.com", "youtube"});
List<string> phones = new List<string>(text.Where(x => x.StartsWith("8") || x.StartsWith("+7")).Select(x => x.Replace("?","")));
List<string> sites = new List<string>(text.Where(x => x.Contains(".") && !x.Contains("@")));
List<string> emails = new List<string>(text.Where(x => x.Contains(".") && x.Contains("@")));
Console.WriteLine(ParseToString(phones));
Console.WriteLine(ParseToString(sites));
Console.WriteLine(ParseToString(emails));
Console.ReadKey();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question