How to remove new line after ":" from a get text value?

how to remove new line after “:” from a get text value? can anyone help me with this?

Can you try using the replace option.
var.Replace (Environment.NewLine,"")

If it’s specifically only the one after “:”, you can use this:

If MyStr is your string variable, then assign it to MyStr.Replace(":" + Environment.NewLine, ":").

1 Like

@Priyanka_Ramesh thanks for ur quick response, i tried with that earlier it works fine. But My output variable contains data like
" Special classes: 1.00.2012,
Students attended today:
(Note:this is a newline that needs to be removed)
Students Absent today:

This is how my text looks like. Here my condition is i need to extract data only if my text contains “students”
My output should be “Students attended today: 100
Students absent today: 12”

Ah, I think I see what’s going on. So there are 2 replacements you’ll need to make. First, assign MyStr as follows:

System.Text.RegularExpressions.Regex.Replace(MyStr, "^" + Environment.Newline, String.Empty)

Then use the first expression I provided:

MyStr.Replace(":" + Environment.NewLine, ":").

This will remove newlines which appear by themselves on a line, and then remove newlines following the “:”.

@Anthony_Humphries Still I’m getting error. Please look into my xaml file. Thanks
Removing_NewLine.xaml (9.0 KB)

System.Text.RegularExpressions.Regex.Replace(MyText, “\s+(\d+)\b”, " $1")

Your XAML post helped a lot. Set TrimmedString to System.Text.RegularExpressions.Regex.Replace(MyString, ":\s*\n+", ": "). You won’t need ReplaceString in this case.


Thanks, that works fine.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.