By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,617 Members | 1,792 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,617 IT Pros & Developers. It's quick & easy.

RegEx replace stuffing spaces

P: n/a
Is there a way to do a Regex replace on a string to stuff some variable
amount of spaces into a location of a string?
I need an expression which would take an unknown length string and move the
last char to position 15.

EX:
123456
transforms to
12345 6

I have a start, but not sure how to do the middle part:
match = "(.*)(.$)"
replace = "$0--spaces go here--$1"
Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Bill,

What about constructing the regular expression dynamically, inserting the
desired number of spaces on the fly? This might be not the best solution if
RegularExpressions have some syntax to populate a number character but I
beleive I haven't seen one.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Bill Mittenzwey" <bm*********@hotmail.com> wrote in message
news:Ou**************@TK2MSFTNGP11.phx.gbl...
Is there a way to do a Regex replace on a string to stuff some variable
amount of spaces into a location of a string?
I need an expression which would take an unknown length string and move the last char to position 15.

EX:
123456
transforms to
12345 6

I have a start, but not sure how to do the middle part:
match = "(.*)(.$)"
replace = "$0--spaces go here--$1"


Jul 21 '05 #2

P: n/a
If you use a MatchEvaluator function when you call Replace(), you can do
this kind of thing fairly easily

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
"Bill Mittenzwey" <bm*********@hotmail.com> wrote in message
news:Ou**************@TK2MSFTNGP11.phx.gbl...
Is there a way to do a Regex replace on a string to stuff some variable
amount of spaces into a location of a string?
I need an expression which would take an unknown length string and move the last char to position 15.

EX:
123456
transforms to
12345 6

I have a start, but not sure how to do the middle part:
match = "(.*)(.$)"
replace = "$0--spaces go here--$1"

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.