Automatic punctuation in the lines of a Multiline Textbox

Asked

Viewed 55 times

1

i need help, it’s like, I have to record the data from a Multiline Textbox to a Database, which is already working, but I have to do an automatic punctuation in that information that was entered by the user, I’ll give an example :

        Isto é a primeira frase; 
        Isto é a segunda frase; 
        Isto é a última frase.

The last sentence will always have to contain a "." and the sentences above that will have to contain a ";", has to be done automatically, in case the user forgets, because this information, will be later exported to a Word document and has to contain this punctuation.

How do I get the program to do it automatically ?

3 answers

0

If it is at runtime, you will have to search for javascript, then I can’t help you much, however, if it is only at the time of insert, you can execute the command replace, changing the line break characters.

Ex: If the content is in HTML:

texto.Replace("<br>",";<br>");

If the string is 'normal' inside the string:

texto.Replace("\r",";\r");

0

To ensure that there will be the ";" I would do the following::

Texto.replace(";", "").replace("\n", ";\n");

And for the "." I would do:

Texto.replace(".", "");
Texto.Insert(Texto.Length, ".")

0


You can use regex and replace

string pattern = @"\s+\n";
string input = @"Isto é a primeira frase 
Isto é a segunda frase  
Isto é a última frase";
Regex.Replace(input,pattern,";\r\n")+"."

Exit:

Isto é a primeira frase;
Isto é a segunda frase;
Isto é a última frase.

See working in .Netfiddle

Browser other questions tagged

You are not signed in. Login or sign up in order to post.