Reg Expressions

  • Thread starter Thread starter krallabandi
  • Start date Start date
K

krallabandi

Can we pad a string with spaces using regular expressions?

Ex: I have a string str = "ABC", I want to pad spaces to the total
string length 10 like "ABC "

how to achieve this using reqular expressions in VB.NET?
 
The short answer to your question is yes, but why not just do something like
this?
Dim str As String = "ABC".PadRight(10, " ")

HTH

Craig
 
Can we pad a string with spaces using regular expressions?

Possibly. The question which springs to mind is why on earth you'd want
to though. There's a perfectly good method for right-padding in the
String class though.
Ex: I have a string str = "ABC", I want to pad spaces to the total
string length 10 like "ABC "

Just use str=str.PadRight(10);

Or is there a reason why you particularly *need* to use regular
expressions?
 
Back
Top