Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi !

 

here's a real pain in the RegEx that is taunting me in some way.

What i need is, convert this couple of line (written here in their general form):

 

Me.VARIABLENAME.Location = New System.Drawing.Point(COORDINATEX, COORDINATEY)

 

*****zero or more possible other lines of code like "Me.VARIABLENAME.SOMETHINGELSE...BLABLABLA"

 

Me.VARIABLENAME.Size = New System.Drawing.Size(WIDTH, HEIGHT)

 

 

 

 

in something like

 

Me.VARIABLENAME.Bounds = New System.Drawing.Rectangle(COORDINATEX, COORDINATEY,WIDTH, HEIGHT)

 

I use the regex of .NET framework and the replace function. The Regex i found is:

 

 

Me\.([a-zA-Z_][_a-zA-Z0-9]*)\.Location = New System\.Drawing\.Point\(([^,]+,[^,]+)\)((.*\n)*)[ \t]*Me\.\1\.Size = New

 

System\.Drawing\.Size\(([^,]+,[^,]+)\)

 

and the possible replacement is:

 

Me.$1.Bounds = New System.Drawing.Rectangle($2,$5)$3

 

 

it almost always works, with 0 or more lines in the middle. Notice that $3 should put all that is inside the two lines,

 

immediately after the last parenthesis in the resulting string.

 

It happens, rarely, something like this: the $3 is placed randomly after a certain number of line, like in the following

 

examlple:

 

 

***************************************

 

'

'dgIncassi

'

Me.dgIncassi.Location = New System.Drawing.Point(0, 26)

Me.dgIncassi.Size = New System.Drawing.Size(238, 220)

'

'TB

'

Me.TB.Buttons.Add(Me.tbCmdExit)

Me.TB.ImageList = Me.IM

'

'tbCmdExit

'

Me.tbCmdExit.ImageIndex = 0

'

'IM

'

Me.IM.Images.Add(CType(resources.GetObject("resource"), System.Drawing.Image))

Me.IM.ImageSize = New System.Drawing.Size(16, 16)

'

 

************************************

 

is converted in:

 

************************************

 

'

'dgIncassi

'

Me.dgIncassi.Bounds = New System.Drawing.Rectangle(0, 26,238, 220)

'

'TB

'

Me.TB.Buttons.Add(Me.tbCmdExit)

Me.TB.ImageList = Me.IM

'

'tbCmdExit

'

Me.tbCmdExit.ImageIndex = 0

'

'IM

'

Me.IM.Images.Add(CType(resources.GetObject("resource")

, System.Drawing.Image))

Me.IM.ImageSize = New System.Drawing.Size(16, 16)

'

**********************************

 

 

 

what is amazing is that in this case $3 is a carriage return and it is placed in the line beginning with Me.IM.Images.Add

The string ", System.Drawing.Image))" comes out actually in a new line but it should follow the line before.

Since this is VB.nET code, i can't afford a carriage return !!

 

Could anyone explain me why in this particular case the $3 is placed not immediately at the end of the regex but some lines later ??

 

Thankx so much !!

 

Wentu

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...