473,327 Members | 2,118 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

RegEx replace stuffing spaces

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
2 3040
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: H | last post by:
This is kind of an followup on oneof my previous questions, and it has with RegEx to do. I have a string containing of several words. What would a good regex expression looklike to get one match...
7
by: bill tie | last post by:
I'd appreciate it if you could advise. 1. How do I replace "\" (backslash) with anything? 2. Suppose I want to replace (a) every occurrence of characters "a", "b", "c", "d" with "x", (b)...
3
by: Jon | last post by:
Hi... I'm getting stumped over the something that MUST be simple...basically, I'm trying to replace the characters 0D0A with a crlf, using Regex.Replace(). The problem is, the replaced string...
5
by: Greg Collins [InfoPath MVP] | last post by:
I couldn't find anything in my searches... I'm wondering if there's a Regex (with or without additional C# code) that can convert a either "lowerCamelCase" or "UpperCamelCase" into a proper "Title...
2
by: Art | last post by:
Hi & help, I'm trying to parse arithmetic expressions such as 4*(7-2.1). The first thing I'm trying is to add spaces to get: 4 * ( 7 - 2.1 ). I thought that Regular Expressions would be the...
2
by: Bill Mittenzwey | last post by:
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...
3
by: Pascal | last post by:
bonjour hello I would like to trim a string of all its white spaces so i used myString.trim() but it doesn't work as supposed : unsecable space are remaining in the middle of my string... i...
4
by: Trev | last post by:
Hi everyone, I'm having some problems using Regex; I have a long string that is delimetered in a random fashion by a combination of spaces and \n's for newlines. I have five possiblities: //...
0
by: Karch | last post by:
I have these two methods that are chewing up a ton of CPU time in my application. Does anyone have any suggestions on how to optimize them or rewrite them without Regex? The most time-consuming...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.