Jump to content

General RegEx Q: is a "List-Replace" possible?


rudi
 Share

Recommended Posts

This is a way:

Global $DATE[12][2] = [["Jan","01"],["Feb","02"],["Mar","03"],["Apr","04"],["May","05"],["Jun","06"],["Jul","07"],["Aug","08"],["Sep","09"],["Oct","10"],["Nov","11"],["Dec","12"]]
Global $DATE_FORMAT = 0

$GUI = GUICreate("EXAMPLE",400,100)
$COMBO = GUICtrlCreateCombo("",5,40,200,390)
$SWITCH = GUICtrlCreateButton("SWITCH",250,40,100,20)
$DATE_ADD = ""
For $INDEX = 0 To 11
    $DATE_ADD &= $DATE[$INDEX][$DATE_FORMAT] & "|"
Next
GUICtrlSetData($COMBO,$DATE_ADD)
GUISetState(@SW_SHOW,$GUI)

While 1
    $MSG = GUIGetMsg()
    If $MSG = $SWITCH Then
        GUICtrlSetData($COMBO,"")
        $DATE_ADD = ""
        $DATE_FORMAT = Not $DATE_FORMAT
        For $INDEX = 0 To 11
            $DATE_ADD &= $DATE[$INDEX][$DATE_FORMAT] & "|"
        Next
        GUICtrlSetData($COMBO,$DATE_ADD)
    ElseIf $MSG = -3 Then
        Exit
    EndIf
    Sleep(20)
WEnd

When the words fail... music speaks.

Link to comment
Share on other sites

Hi.

The topic tells it all.

I currently use 12 times a stringreplace($String,"Jan","01") and so on.

Regards, Rudi.

Here is another attempt.

Local $sString = "January Jan, 21/Feb/2009 20-Mar-2008   19 Apr 2007 May June Jun " & _
        " July jul /August aug /Sept SEP / October Oct / November nov /December DEC"
        
Local $sOldString = $sString, $str, $sString

Local $months[12] = ["jan", "feb", "mar", "apr", "may", "jun", _
                     "jul", "aug", "sep", "oct", "nov", "dec"]

For $x = 0 To 11
    $str = StringFormat("%02d", $x + 1)
    ConsoleWrite($str & @CRLF)
    $sString = StringRegExpReplace($sString, "(?i)\b(" & $months[$x] & ")\b", $str)
Next

MsgBox(0, "RegExpReplace Months", 'Changes "' & $sOldString & '"' & @CRLF & @CRLF & _
        'To' & @tab  & $sString & '"' & @CRLF)
Link to comment
Share on other sites

Hi.

Here is another attempt.

For $x = 0 To 11
    $str = StringFormat("%02d", $x + 1)
    ConsoleWrite($str & @CRLF)
    $sString = StringRegExpReplace($sString, "(?i)\b(" & $months[$x] & ")\b", $str)
Next
A similar loop is what I'm doing right now. I was just wondering, if it would be possible to do these 12 replacements within ONE RegEx?

Thanks, Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Hi.

A similar loop is what I'm doing right now. I was just wondering, if it would be possible to do these 12 replacements within ONE RegEx?

Thanks, Rudi.

OK, then I'll live with looping 12 times :P

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...