How to remove new line in string

Hi Team,

I have one string
status=
“Rejected
2/13/2023” like this
I have one excel with status coloum.when I am extracting each data in string using for each row in datatable activity.
But the output will be
“Rejected
2/13/2023”.

I want string like this
Rejected 2/13/2023 .
I am attaching input sheet for your reference.
!
How to change this input data:
Rejected
2/13/2023
I want Output like this :
Rejected 2/13/2023

Can any one suggest me .

Thanks in advance.
Regards,
Baby

2 Likes

Hi @Baby123 ,

Could you check with the below expression :

String.Join(" ",System.Text.RegularExpressions.Regex.Split(YourInputStr,"\r?\n"))

Hi @supermanPunch,

Thank you so much for quick response.

It’s working

1 Like

@Baby123

You can directly use a replace activity as well

System.Text.RegularExpressions.Regex.Replace(str.Trim,"\r?\n"," ")

Cheers

Hi @Baby123

Try this:

CurrentRow("Status").YoString.ReplaceLineEndings(" ")

Hope it helps!!

Hi
There are many approaches

Let’s go from simple one

  1. StringResult = yourString.Replace(Environment.newLine,“”)

  2. StringResult = String.Join(“ “, Split(yourstring, Environment.Newline))

  3. StringResult = String.Join(“ “, yourString.Split(Environment.NewLine.TocharArray))

  4. stringResult= Regex.Replace(yourString, “\t|\n|\r”, “”)

Hope any of these methods helps

Cheers @Baby123

2 Likes

Hope it’s clarified @Baby123

If yes

Hi you can try this simple way

str = "Rejected
2/13/2023"

System.Text.RegularExpressions.Regex.Replace(str,"\r?\n"," ")

@Baby123

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