Reg Expressions

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?
 
C

Craig Hunt

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
 
J

Jon Skeet [C# MVP]

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top