Answer the question
In order to leave comments, you need to log in
Working with arrays (list) and symbols?
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
List<string> text = ["89192864554","+7926?874?22?44", "[email protected]" , "vk.com", "youtube"];
List<string> phones = new List<string>(text.Where(x => x.StartWith("+") || x.StartWith("8")));
List<string> sites = new List<string>(text.Where(x => x.Contains(".") && !x.Contains("@")));
List<string> email = new List<string>(text.Where(x => x.Contins("@")));
The most banal option is to use regular expressions and pass through the array.
List<string> text = new List<string>(new string[]{"+7920?855?43?55","+7926?874?22?44", "the-appbox.ru" , "vk.com", "+7898?55?6466"});
List<string> phones = new List<string>(text.Where(x => x.StartsWith("+")).Select(x => x.Replace("?","")));
List<string> sites = new List<string>(text.Where(x=>x.Contains(".")));
string phones_str = "";
string sites_str = "";
for (int i=0;i<phones.Count;i++) {
if (i == phones.Count-1)
{
phones_str += phones[i];
break;
}
phones_str += phones[i] + " ";
}
for (int i=0;i<sites.Count;i++) {
if (i == sites.Count-1)
{
sites_str += sites[i];
break;
}
sites_str += sites[i] + " ";
}
Console.WriteLine(phones_str);
Console.WriteLine(sites_str);
Console.ReadKey();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question