How to remove string front space only using regex

Hello,

I want to remove only front space from below sting, so that multi lines remain same
Note: below data is one single string not multi lines but still front space should be removed, can any one help me with regex pattern

Output in text:

  4.50        12 1/4        DRILL          RSS         N   Drill 12-1/4" hole w/ SLB RSS BHA from 9575' to 9,773'.

                                                                   WOB = 2 - 15 klbs.
                                                                   Pump = 1000 gpm .
                                                                   SPP = 3800 - 3900 psi.
                                                                   Rotary = 170 rpm.
                                                                   Torque = 16 / 11 kft-lbs on-btm/off-btm.

And Thank you for explaining the expression!!!..
Thanks in advance
Chethan

that image you given , provide me in text .
write the output how you want

use System.Text.RegularExpressions.Regex.Replace(yourString,“^\s+”,“”,System.Text.RegularExpressions.RegexOptions.Multiline).Trim

Hi @Chethan_M1,

You could use the .TrimStart string function, if you have it in a String variable?

StringVar = StringVar.TrimStart

Hi @Chethan_M1 ,

image

image

image

String.Join(Environment.NewLine, text.Split(Environment.NewLine.ToCharArray, StringSplitOptions.RemoveEmptyEntries).Select(Function(x) x.TrimStart))

Split(Environment.NewLine.ToCharArray, StringSplitOptions.RemoveEmptyEntries): This splits the original string into an array of lines, removing empty entries.
Select(Function(x) x.TrimStart): This applies the TrimStart function to each line in the array.
String.Join(Environment.NewLine, ...): This joins the modified lines back together with newline characters.

I have updated the image data, in text format

what’s this x means, do I need to copy past exactly same expression which you send or need modification

x is a placeholder variable used within a lambda expression.
you can use the same expression.
replace ‘text’ with your string.

Thank you so so much!!!

your string expression works amazing taking only front space with out even braking the table space :clap:

Output
image

Thank you once again
Chethan

1 Like

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