How to Remove the space in between the lines

Southmead Hospital

Tel: 0117 9505050

Address: Southmead Road, Westbury-on-Trym, Bristol, Avon, BS10 5NB

Website: http://www.nbt.nhs.uk

Email: complaints@nbt.nhs.uk

I need the output like this

Southmead Hospital
Tel: 0117 9505050
Address: Southmead Road, Westbury-on-Trym, Bristol, Avon, BS10 5NB
Website: http://www.nbt.nhs.uk
Email: complaints@nbt.nhs.uk

Hi,

There are some ways to achieve it. Hope the following helps you.

System.Text.RegularExpressions.Regex.Replace(yourString,"(\r?\n){2,}",vbcrlf)

or

String.Join(vbcrlf,yourString.Split(vbcrlf.ToCharArray,System.StringSplitoptions.RemoveEmptyEntries))

Regards,

This is working fine. Thanks
System.Text.RegularExpressions.Regex.Replace(yourString,"(\r?\n){2,}",vbcrlf)

1 Like

Could you please help me with this example

1.Withybush General Hospital

Fishguard Road

Haverfordwest

SA61 2PZ

01437 764545

Open 24 hours Open

 Send to mobile
 Services offered
 More Information
 Map/Directions

Output Should be like this

Withybush General Hospital
Fishguard Road
Haverfordwest
SA61 2PZ
01437 764545

Hi,
example for you, as @Yoichi mentioned:

output = String.Join(vbCrLf, your_String.Split(Environment.NewLine.ToArray, StringSplitOptions.RemoveEmptyEntries))
output = String.Join(vbCrLf, your_String.Split(vbCrLf.ToArray, StringSplitOptions.RemoveEmptyEntries))

Remove New Line from whole string:

Replace(vbCr, "") - removes \r [CR (Carriage Return)]
Replace(vbLf, "") - removes \n [LF (Line Feed, Environment.NewLine)]
Replace(vbCrLf, "") - removes \r\n [CR+LF ( End Of Line)]

Remove New Line only from the end of string:

textString.TrimEnd(vbCr.ToCharArray)
textString.TrimEnd(vbCrLf.ToCharArray)
textString.TrimEnd(vbCrLf.ToCharArray)

Check this post:

1 Like

Okay.Thanks

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