Need help in string Manipulation

Hi All,

I have a test like this:

Hi!

I am Anmol.

How are you?

I am good.

There are few lines between the sentences which I don’t want it like the new line between every sentence, for example, there is a new line between"Hi" and “I am Anmol.”
How can I do that?
I want result like this:
Hi!
I am Anmol.
How are you?
I am good.

Thanks!
Anmol

@anmolk171 Regex.Replace(str,"\n"," ") Try to use this and check if it works where str is your string with new line

@anmolk171 Here the new line should be replaced with a space

Hi @anmolk171,

  1. I’ll suggest you to split string using newline

ArrStr = Str.split(Environment.NewLine.TocharArray)
—> ArrStr (Array Of String), str (your string)
—> this remove all newlines from string. As you know there are 2 newlines in every 2 lines.

  1. String join using 1 newline.
    Str = String.Join(Environment.NewLine,ArrStr)
    —>String.join to join array of string using 1 newline as you want it.

  2. writeline —> Str

1 Like

Hi @samir

What is StrString and variable1 in the above code?

Thanks!
Anmol

Oh my bad, now i’ve edited my previous post. @anmolk171

Thanks @samir

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