A
A
Alexey Smirnov2016-03-17 17:11:25
.NET
Alexey Smirnov, 2016-03-17 17:11:25

How to add another line to each word in a line?

Hello.
There is some line:

Классификация енотов. Енот это хищное млекопитающее животное принадлежащее к роду еноты, семейства енотовые.

From this line, I need to extract one word at a time, add another line inside this extracted word, and return this word to its original place. And so repeat for each word in the line.
For example, from the line above we take the first word Классификация, inside it, after the second letter, insert another line: pasteStr="+++"and we get the word Кл+++ассификация, and then we return the resulting word back to the string at its original place:
Кл+++ассификация енотов. Енот это хищное млекопитающее животное принадлежащее к роду еноты, семейства енотовые.

At the same time, the registers of letters in the word remained unchanged, and punctuation marks were preserved.
How can this be implemented?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter, 2016-03-17
@ERAFY

var words = str.Split(' ');
for (int i = 0; i < words.Length; i++)
{
   var word = words[i];
  words[i] = word.Substring(0, 2) + "TEXT" + word.Substring(2); 
}
str = string.Join(' ', words);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question