D
D
DL11112020-12-14 00:13:35
.NET
DL1111, 2020-12-14 00:13:35

There is a character string, in English. How can I replace all letters of the Latin alphabet with a "+" sign?

This string of characters, consisting of free
text in English, words separated by spaces. replace
all letters of the Latin alphabet with the sign "+". Input data using ListBox. strings are entered at the design stage of the form using the properties
window .
Organize the output of the result in the label Label.
I have a code but I don't understand how to do everything as described above
Here is the code:

string alfEng = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz";//английский алфавит
            char[] AA = alfEng.ToCharArray();
            string stroka = "swer rrttyy uu iop!"; //исходная строка
            string resultat = "";//здесь будет результат
            stroka.ToCharArray().All(y=>{if(AA.Contains(y)) resultat+='+'; else resultat+=y; return true;});

Answer the question

In order to leave comments, you need to log in

3 answer(s)
B
BasiC2k, 2020-12-14
@BasiC2k

Use regular expressions. It's fast and easy.

V
Vasily Bannikov, 2020-12-14
@vabka

possible through regehi

var input = "swer rrttyy uu iop!";
var result = Regex.Replace(input, "[a-z]", "+", RegexOptions.IgnoreCase);
Console.WriteLine(result); //++++ ++++++ ++ +++!

V
Vladimir Korotenko, 2020-12-19
@firedragon

Discover ascii all english letters are numbers. Your task is to create a stringbuilder and iterate over the collection of characters in the source string. Inside the loop, check the character for entry into the range; if it is, then add it to the stringbulder + if not, then simply insert this character. I think this is the fastest way

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question