Jump to content

Snippet Dump


czardas
 Share

Recommended Posts



UPDATE

This and other functions in Modal.au3 are no longer supported. These functions have been rewritten and renamed. See spoiler for details and refer to the link in the

_ArrayModalSpin renamed to _ArrayModulate ==> located in arrayf.au3

_ArrayModalSelect renamed to _ArrayLoopSelect ==> located in arrayf.au3

_StringModalSpin renamed to _StringModulate ==> located in stringf.au3

_StringModalSelect renamed to _StringLoopRepeat ==> located in stringf.au3

_bitModalSpin renamed to _BitModulate located in bitwise.au3

_DecToNumBase renamed to _DecToBase located in math10.au3

_NumBaseToDec renamed to _BaseToDec located in math10.au3

_NumBaseToNumBase renamed to _BaseToBase located in math10.au3


_bitModalSpin :D

This function is the same as BitRotate, only without the restrictions imposed by 8, 16 or 32 bit rotation sizes. It is how I had originally perceived the BitRotate function would work; and to me represents nothing less than gold dust: since this code has been eluding me for quite some time.

; #FUNCTION# ============================================================================
; Name...........: _bitModalSpin
; Description ...: Performs a bit shifting operation, with rotation on 2-32 bits
; Syntax.........: _bitModalSpin ( $bVal , $iShift , $iLoopSize )
; Parameters ....: $bVal       - The number to operate on
;                 $iShift    - Number of bits to spin to the left (negative numbers spin right)
;                 $iLoopSize  - The number of bits in the loop - counting from the left
; Return values .: Success   - Returns the value with the required bits rotated
;                 Failure    - Returns zero and sets @error to:
;                |@error = 1  - First parameter is not a valid number or is out of bounds
;                |@error = 2  - Second parameter is not a valid integer
;                |@error = 3  - Third  parameter is not a valid integer or is out of bounds
; Author ........: czardas
; Comments ......; With a loop size of 8, 16 or 32 bits it is faster to use BitRotate.
; ========================================================================================

Func _bitModalSpin($bVal, $iShift, $iLoopSize)
    If (Not IsInt($bVal)) Or ($bVal < 0 - 2^31) Or ($bVal > 2^31 -1) Then Return SetError(1, 0, 0)
    If (Not IsInt($iLoopSize)) Or $iLoopSize > 32 Or $iLoopSize < 0 Then Return SetError(2, 0, 0)
    If Not IsInt($iShift) Then Return SetError(3, 0, 0)

    If $iLoopSize < 2 Then Return $bVal
    $iShift = Mod($iShift, $iLoopSize)
    If $iShift = 0 Then Return $bVal
    If $iLoopSize = 32 Then Return BitRotate($bVal, $iShift, "D") ; Spin all 32 bits

    If $iShift > 0 Then
        $iShift = $iShift - $iLoopSize
    EndIf

    Local $bLeft = BitShift( BitShift($bVal, $iLoopSize), -$iLoopSize)
    Local $bLoop = BitXOR($bLeft, $bVal)
    Local $bRight = BitShift($bLoop, -$iShift)
    Local $bMid = BitShift( BitXOR( BitShift($bRight, $iShift), $bLoop), -$iShift -$iLoopSize)
    Return BitOR($bLeft, $bMid, $bRight)
EndFunc

Example

MsgBox(0, "b10101 ==> b11010", "0x15 ==> 0x1A" & @LF & "Return value = " & _bitModalSpin(21, 1, 4))

Before I wrote this function, bitwise functions were kinda useful to me, but only on a very superficial level. This function changes everything. Now I can modulate a 12 bit loop, without having to rely on using strings. I really don't understand why BitRotate uses the byte as the smallest unit. This fact has caused me so much heartache previously and doesn't seem to make any sense: since in the real world, cycles of 8, 16 and 32 are pretty rare (one or two exceptions aside). Maybe it's just me being a bit 'au contraire'.


The attachment below is the latest version of Modal.au3 which now includes all modal spinning functions for strings, arrays and binary data. The UDF also includes the numeric mode conversion functions seen earlier in this thread.

Modal.au3 ==> Depreciated UDF

I can't think of anything else to spin.

:oops:

Edited by czardas
Link to comment
Share on other sites

  • 7 months later...

Tip Snippet No 1

Pressing the escape key or to close a GUI only works if the GUI has focus. It does not work when the control with focus has been disabled. The following example demonstrates this. Run the example, click the Disable button and then press the Escape key on your keyboard in that order - nothing happens.

#include <GUIConstantsEx.au3>

_FocusExample_1()

Func _FocusExample_1()
    Local $hGUI = GUICreate("Focus Example", 200, 80)
    Local $hButton = GUICtrlCreateButton("Disable",5,5, 70,20)
    Local $hLabelFocus = GUICtrlCreateLabel("Press escape" & @LF & "key to quit", 10, 30, 70, 30)

    GUISetState(@SW_SHOW)

    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $hButton
                GUICtrlSetState($hButton, $GUI_DISABLE)
        EndSwitch
    WEnd
EndFunc

You can change the focus easily enough just by clicking on another window, but the users of your program may not be aware of this. They could think your program is responsible for what could be interpreted as erratic Windows behaviour..One extra line of code is a small price to pay to prevent this. Simply set focus to a control which has not been disabled. Easy as pie!

#include <GUIConstantsEx.au3>

_FocusExample_2()

Func _FocusExample_2()
    Local $hGUI = GUICreate("Focus Example", 200, 80)
    Local $hButton = GUICtrlCreateButton("Disable",5,5, 70,20)
    Local $hLabelFocus = GUICtrlCreateLabel("Press escape" & @LF & "key to quit", 10, 30, 70, 30)

    GUISetState(@SW_SHOW)

    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $hButton
                GUICtrlSetState($hButton, $GUI_DISABLE)
                GUICtrlSetState($hLabelFocus, $GUI_FOCUS)
        EndSwitch
    WEnd
EndFunc

Now your program should always exit when you press the Escape key.

Edited by czardas
Link to comment
Share on other sites

Looking back at some of my earlier code and the comments at the start of this thread make me giggle. Oh boy!

Text Rotation & Geometric Transformation

One of my early programs was a text multiline editor called Line Magic. I still use it today for certain repetitive tasks. One of the missing features I had planned was text rotation to make multiline midline selection possible with the mouse. I wasn't sure how to go about it back then. Today I came across this by UEZ, which I think is pretty neat. UEZ's code reminded me and gave me some insight.

So here's the multiline text version. It's a bit rough and ready, but does the job.

#include <Array.au3>
#include <String.au3>

; Test String
Dim $string = _
"Monday" & @CRLF & _
"Tuesday" & @CRLF & _
"Wednesday" & @CRLF & _
"Thursday" & @CRLF & _
"Friday" & @CRLF & _
"Saturday" & @CRLF & _
"Sunday"

; Rotation Test
For $x = -360 To 360 Step 90
    ConsoleWrite("Rotated " & $x & " degrees" & @LF & _
    _RotateText($string, $x) & @LF & "=========" & @LF)
Next

; Flip Test
ConsoleWrite("Flipped" & @LF & _
_FlipText($string) & @LF & "=========" & @LF)

; Mirror Test
ConsoleWrite("Mirrored" & @LF & _
_MirrorText($string) & @LF & "=========" & @LF)

Func _RotateText($sText, $iDeg = 90, $sDelim = @CRLF)
    If Not StringLen($string) Then Return SetError(1,0,0) ; Not a valid string
    If Mod($iDeg, 90) Then Return SetError(2, 0, 0) ;only 90° rotations allowed

    If $iDeg > 360 Then
        $iDeg -= Floor($iDeg/360)*360
    ElseIf $iDeg < -360 Then
        $iDeg -= Ceiling($iDeg/360)*360
    EndIf

    Local $iMaxStrLen, $aRectangle, $sRotated = ""
    $aRectangle = __ArrayCreateRectangle($sText, $sDelim, $iMaxStrLen)

    Switch $iDeg
        Case 0, 360, -360
            For $i = 1 To $aRectangle[0]
                $sRotated &= $aRectangle[$i] & $sDelim
            Next
        Case 90, -270
            For $i = 1 To $iMaxStrLen
                For $j = $aRectangle[0] To 1 Step -1
                    $sRotated &= StringMid($aRectangle[$j], $i, 1)
                Next
                $sRotated &= $sDelim
            Next
        Case 180, -180
            For $i = $aRectangle[0] To 1 Step -1
                $sRotated &= _StringReverse($aRectangle[$i]) & $sDelim
            Next
        Case 270, -90
            For $i = $iMaxStrLen To 1 Step -1
                For $j = 1 To $aRectangle[0]
                    $sRotated &= StringMid($aRectangle[$j], $i, 1)
                Next
                $sRotated &= $sDelim
            Next
        EndSwitch
    Return StringTrimRight($sRotated, 2)
EndFunc ;==> _RotateText

Func _FlipText($sText, $sDelim = @CRLF)
    If Not StringLen($string) Then Return SetError(1,0,0) ; Not a valid string
    Local $iMaxStrLen, $aRectangle, $sFlipped = ""
    $aRectangle = __ArrayCreateRectangle($sText, $sDelim, $iMaxStrLen)
    For $i = $aRectangle[0] To 1 Step -1
        $sFlipped &= $aRectangle[$i] & $sDelim
    Next
    Return StringTrimRight($sFlipped, 2)
EndFunc ; ==> _FlipText

Func _MirrorText($sText, $sDelim = @CRLF)
    If Not StringLen($string) Then Return SetError(1,0,0) ; Not a valid string
    Local $iMaxStrLen, $aRectangle, $sMirrored = ""
    $aRectangle = __ArrayCreateRectangle($sText, $sDelim, $iMaxStrLen)
    For $i = 1 To $aRectangle[0]
        $sMirrored &= _StringReverse($aRectangle[$i]) & $sDelim
    Next
    Return StringTrimRight($sMirrored, 2)
EndFunc ; ==> _MirrorText

Func __ArrayCreateRectangle($sText, $sDelim, ByRef $iMaxStrLen)
    Local $aRectangle = StringSplit($sText, $sDelim, 1), $aCurrStrLen
    $aCurrStrLen = $aRectangle
    $iMaxStrLen = 0

    For $i = 1 To $aRectangle[0]
        $aCurrStrLen[$i] = StringLen($aRectangle[$i])
        If $aCurrStrLen[$i] > $iMaxStrLen Then $iMaxStrLen = $aCurrStrLen[$i]
    Next
    For $i = 1 To $aRectangle[0]
        $aRectangle[$i] &= _StringRepeat(" ", $iMaxStrLen - $aCurrStrLen[$i])
    Next
    Return $aRectangle
EndFunc ;==> __ArrayCreateRectangle

The retuned text lines are padded out with spaces and always form the shape of a rectangle.

Edited by czardas
Link to comment
Share on other sites

  • 3 weeks later...

Weight and Distance Conversions

For most English speaking nations, having a dual system for measurements can often make life complicated and sometimes lead to serious errors. While I recommend that people should generally stick to using SI units, I have said before that old habits die hard. Hopefully this currently unfinished and sparsely documented library will prove useful to those who need to convert from imperial to metric or astronomical units of measurement.

; Below you will find conversion functions for weight and distance.
; Astronomical data comes from asa.usno.navy.mil/SecK/2013/Astronomical_Constants_2013.pdf
; Function parameters are case sensitive to avoid conflicts with milligram and megagram etc...

; EXAMPLE 1
; Calculate the number of 12 inch pizzas in a cubic gigaparsec of space

$iArea = 6^2 * 22/7 ; area in inches = pi x (r) squared
$iThickness = 1/2 ; estimated thickness of 1/2 inch
$iPizzaVolume = $iArea * $iThickness ; Volume of one pizza in cubic inches
$iCubicGigaparsec = Distance(1, "Gpc", "in")^3 ; Cubic Gpc in cubic inches
$iNumPizzas = $iCubicGigaparsec/$iPizzaVolume

ConsoleWrite("One cubic Gpc of space holds approximately " & $iNumPizzas & " twelve inch pizzas" & @LF)

; EXAMPLE 2
; calculate the weight in solar masses of one cubic gigaparsec of pizzas
; The estimated the mass of one pizza is approximately 1 kg
$iSolarMasses = Weight($iNumPizzas, "kg", "MS")

ConsoleWrite("One cubic Gpc of pizzas weighs approximately " & $iSolarMasses & " solar masses" & @LF)

; Now you can work out the density ratio between a pizza and a star :)

;=====================================================================

#cs
    STANDARD UNITS OF MEASUREMENT (Abbreviated Names)
    µg µm Å a0 ag am angst au cg ch cm Da dag dam dg dm dr Eg Em Et fg fm ft ftm fur g Gg
    Gm Gpc Gt hg hm in kg km kpc kt lb lp ly m mcg mcm ME Mg mg mi MJ MM Mm mm Mpc MS Mt
    ng NM nm nmi oz pc Pg pg Pm pm Pt qtr Tg th Tm Tt u yd Yg yg Ym ym Zg zg Zm zm

    WEIGHT  DEFINITIONS (function parameters)
    µg            microgram
    ag            attogram
    cg            centigram
    Da            Dalton or Atomic Mass Unit
    dag            decagram
    dg            decigram
    dr            drachm or dram
    Eg            exagram
    Et            exatonne
    fg            femtogram
    g            gram
    Gg            gigagram
    Gt            gigatonne
    grain        grain
    hg            hectogram
    kg            kilogram
    kt            kilotonne
    lb            pound
    long cwt    100 weight (British)
    long ton    ton (British)
    mcg            microgram
    ME            Earth mass
    Mg            megagram (1 tonne)
    mg            milligram
    MJ            Jupiter mass
    MM            lunar or moon mass
    MS            solar mass
    Mt            megatonne
    ng            nanogram
    oz            ounce
    Pg            petagram
    pg            picogram
    Pt            petatonne
    qtr            quarter
    short cwt    100 weight (US)
    short ton    ton (US)
    st            stone
    t            metric ton or tonne
    Tg            teragram
    tonne        metric ton
    Tt            teratonne
    u            atomic mass unit or Dalton
    Yg            yottagram
    yg            yoctogram
    Zg            zettagram
    zg            zeptogram

    DISTANCE DEFINITIONS (function parameters)
    µm            micrometre
    Å            angstrom
    a0            Bohr radius
    am            attometre
    angst        angstrom
    au            astronomical unit
    ch            chain
    cm            centimetre
    dam            decametre
    dm            decimetre
    Em            exametre
    fm            femtometre
    ft            foot
    ftm            fathom
    fur            furlong
    Gm            gigametre
    Gpc            gigaparsec
    hm            hectometre
    in            inch
    kpc            kiloparsec
    km            kilometre
    lp            Planck length
    ly            light year
    m            metre
    mcm            micrometer
    mi            mile
    Mm            megametre
    mm            millimetre
    Mpc            megaparsec
    NM            nautical mile
    nm            nanometre
    nmi            nautical mile
    pc            parsec
    Pm            petametre
    pm            picometre
    Tm            terametre
    th            thou
    yd            yard
    Ym            yottametre
    ym            yoctometre
    Zm            zettametre
    zm            zeptometre
#ce

Func Distance($nDistance, $sUnit1, $sUnit2)
    If Not IsNumber($nDistance) Then Return SetError(1, 0, "")
    Local $aUnitTable[39][2] = [ _ ; feet to metres
    [1/12000,             2.54e-5], _ ; th
    [1/12,               2.54e-2], _ ; in
    [1,                 0.3048], _ ; ft
    [3,                 0.9144], _ ; yd
    [6,                 1.8288], _ ; ftm
    [66,                  20.1168], _ ; ch
    [660,               201.168], _ ; fur
    [5280,            1609.344], _ ; mi
    [6075,            1851.66], _ ; NM | nmi
    [5.30249333989501e-35, 1.61619997e-35], _ ; lp
    [1.73614570512369e-10, 5.291772109217e-11], _ ; a0
    [3.28083989501312e-24, 1e-24], _ ; ym
    [3.28083989501312e-21, 1e-21], _ ; zm
    [3.28083989501312e-18, 1e-18], _ ; am
    [3.28083989501312e-15, 1e-15], _ ; fm
    [3.28083989501312e-12, 1e-12], _ ; pm
    [3.28083989501312e-10, 1e-10], _ ; angst | Å
    [3.28083989501312e-9,  1e-9], _ ; nm
    [3.28083989501312e-6,  1e-6], _ ; mcm | µm
    [3.28083989501312e-3,  1e-3], _ ; mm
    [3.28083989501312e-2,  0.01], _ ; cm
    [3.28083989501312e-1,  0.1], _ ; dm
    [3.28083989501312,   1], _ ; m
    [3.28083989501312e+1,  10], _ ; dam
    [3.28083989501312e+2,  100], _ ; hm
    [3.28083989501312e+3,  1e+3], _ ; km
    [3.28083989501312e+6,  1e+6], _ ; Mm
    [3.28083989501312e+9,  1e+9], _ ; Gm
    [3.28083989501312e+12, 1e+12], _ ; Tm
    [3.28083989501312e+15, 1e+15], _ ; Pm
    [3.28083989501312e+18, 1e+18], _ ; Em
    [3.28083989501312e+21, 1e+21], _ ; Zm
    [3.28083989501312e+24, 1e+24], _ ; Ym
    [4.90806662401575e+11, 1.495978707e+11], _ ; au
    [3.10391419704094e+16, 9.4607304725808e+15], _ ; ly
    [1.01236141124252e+17, 3.08567758146719e+16], _ ; pc
    [1.01236141124252e+20, 3.08567758146719e+19], _ ; kpc
    [1.01236141124252e+23, 3.08567758146719e+22], _ ; Mpc
    [1.01236141124252e+26, 3.08567758146719e+25]] ; Gpc

    $iIndex1 = __GetUnitIndex($sUnit1,"distance")
    If @error Then Return SetError (2, 0, "") ; UDF version return value
    $iIndex2 = __GetUnitIndex($sUnit2,"distance")
    If @error Then Return SetError (3, 0, "") ; UDF version return value

    If $iIndex1 < 9 Then ; Imperial system
        $nDistance *= $aUnitTable[$iIndex1][0] ; Convert to feet
        $nDistance /= $aUnitTable[$iIndex2][0] ; Convert to new unit
    Else ; Metric or astronomic system
        $nDistance *= $aUnitTable[$iIndex1][1] ; Convert to metres
        $nDistance /= $aUnitTable[$iIndex2][1] ; Convert to new unit
    EndIf

    Return $nDistance
EndFunc

Func Weight($nWeight, $sUnit1, $sUnit2)
    If Not IsNumber($nWeight) Then Return SetError(1, 0, "")
    Local $aUnitTable[36][2] = [ _ ; Pounds to grams
    [1/7000,               0.06479891], _ ; grain
    [1/256,             1.7718451953125], _ ; dr
    [1/16,              28.349523125], _ ; oz
    [1,               453.59237], _ ; lb
    [14,                6350.29318], _ ; st
    [28,               12700.58636], _ ; qtr
    [100,             45359.237], _ ; short cwt
    [112,             50802.34544], _ ; long cwt
    [2000,          907184.74], _ ; short ton
    [2240,         1016046.9088], _ ; long ton
    [3.66086167130633e-27, 1.66053892173e-24], _ ; Da | u
    [2.20462262184878e-27, 1e-24], _ ; yg
    [2.20462262184878e-24, 1e-21], _ ; zg
    [2.20462262184878e-21, 1e-18], _ ; ag
    [2.20462262184878e-18, 1e-15], _ ; fg
    [2.20462262184878e-15, 1e-12], _ ; pg
    [2.20462262184878e-12, 1e-9], _ ; ng
    [2.20462262184878e-9,  1e-6], _ ; mcg | µg
    [2.20462262184878e-6,  1e-3], _ ; mg
    [2.20462262184878e-5,  0.01], _ ; cg
    [2.20462262184878e-4,  0.1], _ ; dg
    [2.20462262184878e-3,  1], _ ; g
    [2.20462262184878e-2,  10], _ ; dag
    [2.20462262184878e-1,  100], _ ; hg
    [2.20462262184878,   1e+3], _ ; kg
    [2.20462262184878e+3,  1e+6], _ ; t | Mg | tonne
    [2.20462262184878e+9,  1e+9], _ ; kt | Gg
    [2.20462262184878e+12, 1e+12], _ ; Mt | Tg
    [2.20462262184878e+15, 1e+15], _ ; Gt | Pg
    [2.20462262184878e+18, 1e+18], _ ; Tt | Eg
    [2.20462262184878e+21, 1e+21], _ ; Pt | Zg
    [2.20462262184878e+24, 1e+24], _ ; Et | Yg
    [1.61947789308317e+23, 7.345828156862e+25], _ ; MM
    [1.31664472222053e+25, 5.9722e+27], _ ; ME
    [4.1854941488654e+27,  1.89850821060499e+30], _ ; MJ
    [4.38367162128411e+30, 1.9884e+33]] ; MS

    $iIndex1 = __GetUnitIndex($sUnit1,"weight")
    If @error Then Return SetError (2, 0, "") ; UDF version return value
    $iIndex2 = __GetUnitIndex($sUnit2,"weight")
    If @error Then Return SetError (3, 0, "") ; UDF version return value

    If $iIndex1 < 10 Then ; Avoirdupois or pound unit system
        $nWeight *= $aUnitTable[$iIndex1][0] ; Convert to pounds
        $nWeight /= $aUnitTable[$iIndex2][0] ; Convert to new unit
    Else ; Metric or astronomic system
        $nWeight *= $aUnitTable[$iIndex1][1] ; Convert to grams
        $nWeight /= $aUnitTable[$iIndex2][1] ; Convert to new unit
    EndIf

    Return $nWeight
EndFunc

Func __GetUnitIndex($sUnit, $sMesurement)
    $sUnit = StringStripWS($sUnit, 7)
    Switch $sMesurement
        Case "weight"
            Local $aAbbr[46] = ["grain", "dr","oz","lb","st","qtr","short cwt","long cwt","short ton","long ton","Da", _
            "yg","zg","ag","fg","pg","ng","mcg","mg","cg","dg","g","dag","hg","kg","t","kt","Mt","Gt","Tt","Pt","Et", _
            "MM","ME","MJ","MS","Mg","Gg","Tg","Pg","Eg","Zg","Yg","u","µg","tonne"]

            For $i = 0 To 45
                If $sUnit == $aAbbr[$i] Then
                    Switch $i
                        Case 0 To 35
                            Return $i
                        Case 36 To 42
                            Return $i - 11
                        Case 43
                            Return 10
                        Case 44
                            Return 17
                        Case 45
                            Return 25
                    EndSwitch
                EndIf
            Next
            Return SetError (1)

        Case "distance"
            Local $aAbbr[42] = ["th","in","ft","yd","ftm","ch","fur","mi","NM","lp","a0","ym","zm","am","fm", _
            "pm","angst","nm","mcm","mm","cm","dm","m","dam","hm","km","Mm","Gm","Tm","Pm","Em","Zm","Ym", _
            "au","ly","pc","kpc","Mpc","Gpc","nmi","Å","µm"]

            For $i = 0 To 41
                If StringStripWS($sUnit, 7) == $aAbbr[$i] Then
                    Switch $i
                        Case 0 To 38
                            Return $i
                        Case 49
                            Return 8
                        Case 40
                            Return 16
                        Case 41
                            Return 18
                    EndSwitch
                EndIf
            Next
            Return SetError (1)
    EndSwitch
EndFunc
Link to comment
Share on other sites

  • 2 weeks later...

Roman Numerals

Several of the functions I have posted recently are part of a larger project. Roman numerals are sometimes a useful alternative to Arabic numerals, although they are generally only used in technical documents to number the pages of an appendix.

Mat has also created some functions which include a Roman numerals system. There is a slight difference here. The conversion to Roman numerals is limited to numbers in the range from 1 to 3999. Information was taken from wiki.

For $j = 1 To 3999
    ConsoleWrite(_RomanNumerals($j) & @CRLF)
Next

Func _RomanNumerals($iInt)
    If Not IsInt($iInt) Or $iInt > 3999 Or $iInt < 1 Then Return SetError(1, 0, "")

    Local $aNumeral[10][4] = _
    [["","","",""], _
    ["M","C","X","I"], _
    ["MM","CC","XX","II"], _
    ["MMM","CCC","XXX","III"], _
    ["","CD","XL","IV"], _
    ["","D","L","V"], _
    ["","DC","LX","VI"], _
    ["","DCC","LXX","VII"], _
    ["","DCCC","LXXX","VIII"], _
    ["","CM","XC","IX"]]

    Local $iOffset = StringLen($iInt) -4, $sRoman = "", $aDecimal = StringSplit($iInt, "", 2)
    For $i = 0 To UBound($aDecimal) -1
        $sRoman &= $aNumeral[$aDecimal[$i]][$i -$iOffset]
    Next

    Return $sRoman
EndFunc

I didn't write the reverse function because I don't intend to use it. Perhaps someone else might like to do that. :)

Edited by czardas
Link to comment
Share on other sites

  • 3 weeks later...

Tip Snippet No 2

After getting all mixed up regarding this subject previously in Help and Support and missing the target completely, I came up with a very simple idea to solve the problem of error checking within nested functions once and for all. Without proper access to a compiuter, I didn't get the opportunity to test this out until today. The problem is simple, as is the solution. After exiting a function, any error that has been thrown can not be checked when the function is nested; at least not without some kind of customised error handling. So if you nest UDF functions, it is possible to use a method similar to the one demonstrated below when the fail point can easily determind.

Global $g_KickBack_ = 0 ; This is our error count

_FuncNestTest()

Func _FuncNestTest()
    Local $ret = "accepted"
    _CheckError(_CheckError(_CheckError(_CheckError(_CheckError($ret))))) ; Here five UDF functions are nested, could be anything.
    MsgBox(0, "Hard Error", "Failure occured at nested function number : " & 5 - $g_KickBack_ + 1) ; Function Calls - errors + 1 (base count)
EndFunc

Func _CheckError($vParam)
    If $g_KickBack_ > 0 Then
        $g_KickBack_ += 1 ; Tracking the fail point
        Return SetError(1, 0, "la di da di da")
    EndIf

    ; General error testing ... Can be anything
    If $vParam <> "accepted" Then
        $g_KickBack_ += 1 ; Tracking the fail point
        Return SetError(2, 0, "la di da di da")
    EndIf

    ; Invoke failure on the 2nd run - simulated function
    Return StringTrimLeft($vParam, 1)
EndFunc
Link to comment
Share on other sites

  • 3 months later...

Shuffle the elements within a Multidimensional Array

I was trying to be clever using a recursive function for this, but it got too confusing. So I have created a small monster instead. This function will shuffle a multidimensional array of up to 11 dimensions. When I say shuffle - I mean any element can end up anywhere in any dimension.

#include <Array.au3> ; For _ArrayDisplay

#region ; Example
Global $aGrid[4][4] = [[0,1,2,3],[4,"",5,6],[7,8,0,9],["a","b","c",""]]
_ArrayDisplay($aGrid)

For $i = 0 To 9
    _ArrayShuffleMultiDim($aGrid)
    _ArrayDisplay($aGrid)
Next
#endregion

Func _ArrayShuffleMultiDim(ByRef $aArray)
    If IsArray($aArray) = 0 Then Return SetError (1)

    Local $iDim = UBound($aArray, 0) ; Get No dimensions
    If $iDim > 11 Then Return SetError (2)

    Local $a[$iDim +1], $aiBound[12] = [0,0,0,0,0,0,0,0,0,0,0,0]
    For $i = 1 To $iDim ; For each dimensionn
        $aiBound[$i] = UBound($aArray, $i) -1 ; Get dimension size
    Next

    For $i = 0 To $aiBound[1]
        For $j = 0 To $aiBound[2]
            For $k = 0 To $aiBound[3]
                For $l = 0 To $aiBound[4]
                    For $m = 0 To $aiBound[5]
                        For $n = 0 To $aiBound[6]
                            For $o = 0 To $aiBound[7]
                                For $p = 0 To $aiBound[8]
                                    For $q = 0 To $aiBound[9]
                                        For $r = 0 To $aiBound[10]
                                            For $s = 0 To $aiBound[11]
                                                For $z = 1 To $iDim
                                                    ; Get random values for each dimension.
                                                    $a[$z] = Random(0, $aiBound[$z], 1)
                                                Next
                                                __Swap($aArray, $iDim, $a, $i, $j, $k, $l, $m, $n, $o, $p, $q, $r, $s)
                                            Next
                                        Next
                                    Next
                                Next
                            Next
                        Next
                    Next
                Next
            Next
        Next
    Next
EndFunc

Func __Swap(ByRef $aArray, $iDim, $a, $i, $j, $k, $l, $m, $n, $o, $p, $q, $r, $s)
    Local $vTemp
    Switch $iDim
        Case 1
            $vTemp = $aArray[$i]
            $aArray[$i] = $aArray[$a[1]]
            $aArray[$a[1]] = $vTemp
        Case 2
            $vTemp = $aArray[$i][$j]
            $aArray[$i][$j] = $aArray[$a[1]][$a[2]]
            $aArray[$a[1]][$a[2]] = $vTemp
        Case 3
            $vTemp = $aArray[$i][$j][$k]
            $aArray[$i][$j][$k] = $aArray[$a[1]][$a[2]][$a[3]]
            $aArray[$a[1]][$a[2]][$a[3]] = $vTemp
        Case 4
            $vTemp = $aArray[$i][$j][$k][$l]
            $aArray[$i][$j][$k][$l] = $aArray[$a[1]][$a[2]][$a[3]][$a[4]]
            $aArray[$a[1]][$a[2]][$a[3]][$a[4]] = $vTemp
        Case 5
            $vTemp = $aArray[$i][$j][$k][$l][$m]
            $aArray[$i][$j][$k][$l][$m] = $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]]
            $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]] = $vTemp
        Case 6
            $vTemp = $aArray[$i][$j][$k][$l][$m][$n]
            $aArray[$i][$j][$k][$l][$m][$n] = $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]]
            $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]] = $vTemp
        Case 7
            $vTemp = $aArray[$i][$j][$k][$l][$m][$n][$o]
            $aArray[$i][$j][$k][$l][$m][$n][$o] = $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]][$a[7]]
            $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]][$a[7]] = $vTemp
        Case 8
            $vTemp = $aArray[$i][$j][$k][$l][$m][$n][$o][$p]
            $aArray[$i][$j][$k][$l][$m][$n][$o][$p] = $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]][$a[7]][$a[8]]
            $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]][$a[7]][$a[8]] = $vTemp
        Case 9
            $vTemp = $aArray[$i][$j][$k][$l][$m][$n][$o][$p][$q]
            $aArray[$i][$j][$k][$l][$m][$n][$o][$p][$q] = $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]][$a[7]][$a[8]][$a[9]]
            $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]][$a[7]][$a[8]][$a[9]] = $vTemp
        Case 10
            $vTemp = $aArray[$i][$j][$k][$l][$m][$n][$o][$p][$q][$r]
            $aArray[$i][$j][$k][$l][$m][$n][$o][$p][$q][$r] = $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]][$a[7]][$a[8]][$a[9]][$a[10]]
            $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]][$a[7]][$a[8]][$a[9]][$a[10]] = $vTemp
        Case 11
            $vTemp = $aArray[$i][$j][$k][$l][$m][$n][$o][$p][$q][$r][$s]
            $aArray[$i][$j][$k][$l][$m][$n][$o][$p][$q][$r][$s] = $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]][$a[7]][$a[8]][$a[9]][$a[10]][$a[11]]
            $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]][$a[7]][$a[8]][$a[9]][$a[10]][$a[11]] = $vTemp
    EndSwitch
EndFunc

Other than setting up a game of battleships, I can't think of many uses for shuffling a multidimensional array. If anyone can suggest any potential uses for this I would love to hear your ideas.

Edited by czardas
Link to comment
Share on other sites

Walk Through a 3D Array

We can walk through a 3 dimensional array by displaying a sequence of 2 dimensional grids. Getting one's bearings with a 3D array walk through can be slightly confusing. The grids could be arranged in a horizontal stack, or vertically like books on a shelf. I have chosen the standard x, y and z axes to represent 3D orientation and grid sequence.

The orientation parameter $sOrientation is formed by two of the letters. For example the letters 'yx' represent a standard 2D grid with axes y and x in sequence. Any combination of two axis letters can be used as a second parameter, allowing you to view the array from six different persectives.

This script was designed for testing, and helped me to discover a bug in, the array shuffle algorithm above.

#include <Array.au3>

; Example of 3D array walk through:

Global $aArray[4][3][3] = _
[[["A","B","C"],["D","E","F"],["G","H","I"]], _ ; First table is the default orientation
[["J","K","L"],["M","N","O"],["P","Q","R"]], _
[["S","T","U"],["V","W","X"],["Y","Z","0"]], _
[["1","2","3"],["4","5","6"],["7","8","9"]]]

MsgBox(0, "Message", "First we walk through the array")
_Array3DWalkThrough($aArray)

MsgBox(0, "Message", "Now the array will be shuffled")
_ArrayShuffleMultiDim($aArray)
_Array3DWalkThrough($aArray)

Func _Array3DWalkThrough($aArray, $sOrientation = "yx")
    If UBound($aArray, 0) <> 3 Then Return SetError(1) ; Not a 3D array

    Local $aiBound[4]
    For $i = 1 To 3 ; Get the size of each dimension
        $aiBound[$i] = UBound($aArray, $i)
    Next

    Switch $sOrientation
        Case "yx" ; Default orientation
            Local $aDisplay[$aiBound[2]][$aiBound[3]]
            For $y = 0 To $aiBound[1] -1
                For $x = 0 To $aiBound[2] -1
                    For $z = 0 To $aiBound[3] -1
                        $aDisplay[$x][$z] = $aArray[$y][$x][$z]
                    Next
                Next
                _ArrayDisplay($aDisplay, "Grid " & $y +1)
            Next

        Case "zx" ; Horizontal Stack
            Local $aDisplay[$aiBound[1]][$aiBound[3]]
            For $x = 0 To $aiBound[2] -1
                For $y = 0 To $aiBound[1] -1
                    For $z = 0 To $aiBound[3] -1
                        $aDisplay[$y][$z] = $aArray[$y][$x][$z]
                    Next
                Next
                _ArrayDisplay($aDisplay, "Grid " & $x +1)
            Next

        Case "zy" ; Vertical Alignment
            Local $aDisplay[$aiBound[1]][$aiBound[2]]
            For $z = 0 To $aiBound[3] -1
                For $y = 0 To $aiBound[1] -1
                    For $x = 0 To $aiBound[2] -1
                        $aDisplay[$y][$x] = $aArray[$y][$x][$z]
                    Next
                Next
                _ArrayDisplay($aDisplay, "Grid " & $z +1)
            Next

        Case "xy" ; Default rotated 90 degees
            Local $aDisplay[$aiBound[3]][$aiBound[2]]
            For $y = 0 To $aiBound[1] -1
                For $z = 0 To $aiBound[3] -1
                    For $x = 0 To $aiBound[2] -1
                        $aDisplay[$z][$x] = $aArray[$y][$x][$z]
                    Next
                Next
                _ArrayDisplay($aDisplay, "Grid " & $y +1)
            Next

        Case "xz" ; Horizontal Stack rotated 90 degees
            Local $aDisplay[$aiBound[3]][$aiBound[1]]
            For $x = 0 To $aiBound[2] -1
                For $z = 0 To $aiBound[3] -1
                    For $y = 0 To $aiBound[1] -1
                        $aDisplay[$z][$y] = $aArray[$y][$x][$z]
                    Next
                Next
                _ArrayDisplay($aDisplay, "Grid " & $x +1)
            Next

        Case "yz" ; Vertical Alignment rotated 90 degees
            Local $aDisplay[$aiBound[2]][$aiBound[1]]
            For $z = 0 To $aiBound[3] -1
                For $x = 0 To $aiBound[2] -1
                    For $y = 0 To $aiBound[1] -1
                        $aDisplay[$x][$y] = $aArray[$y][$x][$z]
                    Next
                Next
                _ArrayDisplay($aDisplay, "Grid " & $z +1)
            Next

        Case Else
            Return SetError(2) ; Incorrect second parameter
    EndSwitch
EndFunc ;==> _Array3DWalkThrough


#region ; Functions related to the example

Func _ArrayShuffleMultiDim(ByRef $aArray)
    If IsArray($aArray) = 0 Then Return SetError (1)

    Local $iDim = UBound($aArray, 0) ; Get No dimensions
    If $iDim > 11 Then Return SetError (2)

    Local $a[$iDim +1], $aiBound[12] = [0,0,0,0,0,0,0,0,0,0,0,0]
    For $i = 1 To $iDim ; For each dimensionn
        $aiBound[$i] = UBound($aArray, $i) -1 ; Get dimension size
    Next

    For $i = 0 To $aiBound[1]
        For $j = 0 To $aiBound[2]
            For $k = 0 To $aiBound[3]
                For $l = 0 To $aiBound[4]
                    For $m = 0 To $aiBound[5]
                        For $n = 0 To $aiBound[6]
                            For $o = 0 To $aiBound[7]
                                For $p = 0 To $aiBound[8]
                                    For $q = 0 To $aiBound[9]
                                        For $r = 0 To $aiBound[10]
                                            For $s = 0 To $aiBound[11]
                                                For $z = 1 To $iDim
                                                    ; Get random values for each dimension.
                                                    $a[$z] = Random(0, $aiBound[$z], 1)
                                                Next
                                                __Swap($aArray, $iDim, $a, $i, $j, $k, $l, $m, $n, $o, $p, $q, $r, $s)
                                            Next
                                        Next
                                    Next
                                Next
                            Next
                        Next
                    Next
                Next
            Next
        Next
    Next
EndFunc ;==> _ArrayShuffleMultiDim

Func __Swap(ByRef $aArray, $iDim, $a, $i, $j, $k, $l, $m, $n, $o, $p, $q, $r, $s)
    Local $vTemp
    Switch $iDim
        Case 1
            $vTemp = $aArray[$i]
            $aArray[$i] = $aArray[$a[1]]
            $aArray[$a[1]] = $vTemp
        Case 2
            $vTemp = $aArray[$i][$j]
            $aArray[$i][$j] = $aArray[$a[1]][$a[2]]
            $aArray[$a[1]][$a[2]] = $vTemp
        Case 3
            $vTemp = $aArray[$i][$j][$k]
            $aArray[$i][$j][$k] = $aArray[$a[1]][$a[2]][$a[3]]
            $aArray[$a[1]][$a[2]][$a[3]] = $vTemp
        Case 4
            $vTemp = $aArray[$i][$j][$k][$l]
            $aArray[$i][$j][$k][$l] = $aArray[$a[1]][$a[2]][$a[3]][$a[4]]
            $aArray[$a[1]][$a[2]][$a[3]][$a[4]] = $vTemp
        Case 5
            $vTemp = $aArray[$i][$j][$k][$l][$m]
            $aArray[$i][$j][$k][$l][$m] = $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]]
            $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]] = $vTemp
        Case 6
            $vTemp = $aArray[$i][$j][$k][$l][$m][$n]
            $aArray[$i][$j][$k][$l][$m][$n] = $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]]
            $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]] = $vTemp
        Case 7
            $vTemp = $aArray[$i][$j][$k][$l][$m][$n][$o]
            $aArray[$i][$j][$k][$l][$m][$n][$o] = $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]][$a[7]]
            $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]][$a[7]] = $vTemp
        Case 8
            $vTemp = $aArray[$i][$j][$k][$l][$m][$n][$o][$p]
            $aArray[$i][$j][$k][$l][$m][$n][$o][$p] = $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]][$a[7]][$a[8]]
            $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]][$a[7]][$a[8]] = $vTemp
        Case 9
            $vTemp = $aArray[$i][$j][$k][$l][$m][$n][$o][$p][$q]
            $aArray[$i][$j][$k][$l][$m][$n][$o][$p][$q] = $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]][$a[7]][$a[8]][$a[9]]
            $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]][$a[7]][$a[8]][$a[9]] = $vTemp
        Case 10
            $vTemp = $aArray[$i][$j][$k][$l][$m][$n][$o][$p][$q][$r]
            $aArray[$i][$j][$k][$l][$m][$n][$o][$p][$q][$r] = $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]][$a[7]][$a[8]][$a[9]][$a[10]]
            $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]][$a[7]][$a[8]][$a[9]][$a[10]] = $vTemp
        Case 11
            $vTemp = $aArray[$i][$j][$k][$l][$m][$n][$o][$p][$q][$r][$s]
            $aArray[$i][$j][$k][$l][$m][$n][$o][$p][$q][$r][$s] = $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]][$a[7]][$a[8]][$a[9]][$a[10]][$a[11]]
            $aArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]][$a[7]][$a[8]][$a[9]][$a[10]][$a[11]] = $vTemp
    EndSwitch
EndFunc ;==> __Swap

#endregion

And a second example which demonstrates all six perspectives.using the second parameter

#include <Array.au3>

Global $aArray[4][3][2] = _
[[["000","001"],["010","011"],["020","021"]], _
[["100","101"],["110","111"],["120","121"]], _
[["200","201"],["210","211"],["220","221"]], _
[["300","301"],["310","311"],["320","321"]]]

_Array3DWalkThrough($aArray)
_Array3DWalkThrough($aArray, "zx")
_Array3DWalkThrough($aArray, "zy")
_Array3DWalkThrough($aArray, "xy")
_Array3DWalkThrough($aArray, "xz")
_Array3DWalkThrough($aArray, "yz")

Func _Array3DWalkThrough($aArray, $sOrientation = "yx")
    If UBound($aArray, 0) <> 3 Then Return SetError(1) ; Not a 3D array

    Local $aiBound[4]
    For $i = 1 To 3 ; Get the size of each dimension
        $aiBound[$i] = UBound($aArray, $i)
    Next

    Switch $sOrientation
        Case "yx" ; Default orientation
            Local $aDisplay[$aiBound[2]][$aiBound[3]]
            For $y = 0 To $aiBound[1] -1
                For $x = 0 To $aiBound[2] -1
                    For $z = 0 To $aiBound[3] -1
                        $aDisplay[$x][$z] = $aArray[$y][$x][$z]
                    Next
                Next
                _ArrayDisplay($aDisplay, "Grid " & $y +1)
            Next

        Case "zx" ; Horizontal Stack
            Local $aDisplay[$aiBound[1]][$aiBound[3]]
            For $x = 0 To $aiBound[2] -1
                For $y = 0 To $aiBound[1] -1
                    For $z = 0 To $aiBound[3] -1
                        $aDisplay[$y][$z] = $aArray[$y][$x][$z]
                    Next
                Next
                _ArrayDisplay($aDisplay, "Grid " & $x +1)
            Next

        Case "zy" ; Vertical Alignment
            Local $aDisplay[$aiBound[1]][$aiBound[2]]
            For $z = 0 To $aiBound[3] -1
                For $y = 0 To $aiBound[1] -1
                    For $x = 0 To $aiBound[2] -1
                        $aDisplay[$y][$x] = $aArray[$y][$x][$z]
                    Next
                Next
                _ArrayDisplay($aDisplay, "Grid " & $z +1)
            Next

        Case "xy" ; Default rotated 90 degees
            Local $aDisplay[$aiBound[3]][$aiBound[2]]
            For $y = 0 To $aiBound[1] -1
                For $z = 0 To $aiBound[3] -1
                    For $x = 0 To $aiBound[2] -1
                        $aDisplay[$z][$x] = $aArray[$y][$x][$z]
                    Next
                Next
                _ArrayDisplay($aDisplay, "Grid " & $y +1)
            Next

        Case "xz" ; Horizontal Stack rotated 90 degees
            Local $aDisplay[$aiBound[3]][$aiBound[1]]
            For $x = 0 To $aiBound[2] -1
                For $z = 0 To $aiBound[3] -1
                    For $y = 0 To $aiBound[1] -1
                        $aDisplay[$z][$y] = $aArray[$y][$x][$z]
                    Next
                Next
                _ArrayDisplay($aDisplay, "Grid " & $x +1)
            Next

        Case "yz" ; Vertical Alignment rotated 90 degees
            Local $aDisplay[$aiBound[2]][$aiBound[1]]
            For $z = 0 To $aiBound[3] -1
                For $x = 0 To $aiBound[2] -1
                    For $y = 0 To $aiBound[1] -1
                        $aDisplay[$x][$y] = $aArray[$y][$x][$z]
                    Next
                Next
                _ArrayDisplay($aDisplay, "Grid " & $z +1)
            Next

        Case Else
            Return SetError(2) ; Incorrect second parameter
    EndSwitch
EndFunc ;==> _Array3DWalkThrough
Edited by czardas
Link to comment
Share on other sites

  • 4 weeks later...

_ConvertToANSI

Removes all characters not appearing in the default extended ASCII character set on your local machine. Results will depend on the code page used by your system. It is said that a function ought to always return the same results with the same input. If only it were true. >_<

Instead of deleting characters, you can include a second parameter as a replacement string.

Func _ConvertToANSI($sText, $sSub = "")
    If Not IsString($sText) Then Return SetError(1, 0, "")

    Local $sAscEx = "" ; Extended AscII
    For $i = 128 To 255
        $sAscEx &= Chr($i)
    Next

    Return StringRegExpReplace($sText, "[^" & $sAscEx & "\x00-\x7F]", $sSub)
EndFunc

Copy this line which containing Chinese characters - 例如,在中國 to the clipboard, and run the example below.

Test()

Func Test()
Local $string = ClipGet()
MsgBox(0, "Before", $string)

$string = _ConvertToANS($string)
If Not @error Then
     MsgBox(0, "After", $string)
Else
     MsgBox(0, "ERROR", "Failed to convert.")
EndIf
EndFunc ; ==> Test
Edited by czardas
Link to comment
Share on other sites

  • 3 weeks later...

Unicode Compatible Title Case

This topic has come up quite a lot lately and the following code is really an experiment. Problems associated with proper case are not all possible to resolve. Differentiating between words and acronyms, or identifying common exceptions such as Scottish names beginning Mac or Mc, is very hard. MC is also a Roman numeral. The function does not attempt any of these things. Instead it avoids altering anything which may already be correct. It will not touch abbreviations such as BBC or website URLs and it also caters for various types of hyphenation and apostrophies. You have the option to ignore small word exceptions which are not capitalized in standard British English.

After you have run the example try using the function on the actual code itself. Mainly the comments will be capitalized and the code will remain mainly untouched and still run, because pre-existing capitals are presumed to be correct. I wrote all the comments in lower case on purpose so you could try this.

Rules and Guidelines

Capitalizes

The first word - if it isn't on the ignore list

The last word - if isn't on the ignore list

All other words with (optional) exceptions - listed below:

a, an, and, as, at, but, by, for, from, in, into, nor,

of, on, onto, or, per, so, the, to, up, via, with, yet

Ignore List

Ignores strings containing capitals

Ignores strings containing numbers

Ignores strings containing underscore

Ignores URLs and file paths without spaces

Ignores alpha characters preceeded by a hyphen

Ignores alpha characters preceeded by an apostrophe

#include-once
#include <Array.au3>
#include <String.au3>

Example()

Func Example()
    Local $sExample = _
    "the great rock 'n roll swindle" & @LF & _
    "old McDonnald had a farm" & @LF & _
    "download AutoIt from autoitscript.com." & @LF & _
    "download win-1252 from autoitscript.com/forum/topic/135167-win-1252-extended-keyboard/" & @LF & _
    "from the 14th to the 21st century" & @LF & _
    "BBC iTunes II III IV" & @LF & _
    "la época de los árabes" & @LF & _
    "on (and on) and on" & @LF & _
    "on top of old smokey" & @LF & _
    "she's got x-ray vision" & @LF &  _
    "one,two,three,four" & @LF &  _
    "werner von bruin" & @LF &  _
    "paco de lucía y camarón de la isla"

    ConsoleWrite(_TitleCase($sExample, Default, Default, True) & @LF)
EndFunc ;==> Example()

Func _TitleCase($sText, $bAP_Exceptions = True, $bIgnoreCaps = True, $bInternational = False, $bIgnoreURL = True)
    If Not StringLen($sText) Then Return SetError(1, 0, $sText) ; nothing to parse
    If $bAP_Exceptions = Default Then $bAP_Exceptions = True
    If $bIgnoreCaps = Default Then $bIgnoreCaps = True
    If $bInternational = Default Then $bInternational = False
    If $bIgnoreURL = Default Then $bIgnoreURL = True

    Local $sWSLeft = "", $sWSRight = "", $sCurrChar
    For $i = 1 To StringLen($sText)
        $sCurrChar = StringMid($sText, $i, 1)
        If StringRegExp($sCurrChar, "\s") Then
            $sWSLeft &= $sCurrChar ; get leading WS
        Else
            ExitLoop
        EndIf
    Next

    For $i = StringLen($sText) To 1 Step -1
        $sCurrChar = StringMid($sText, $i, 1)
        If StringRegExp($sCurrChar, "\s") Then
            $sWSRight = $sCurrChar & $sWSRight ; get trailing WS
        Else
            ExitLoop
        EndIf
    Next

    $sText = StringStripWS($sText, 3) ; remove leading and trailing WS

    Local $sNewStr = "", $sRegExp = "[0-9]|_", $bExceptions = False    
    If $bIgnoreURL Then $sRegExp &= "|\\|/|(\.\w)"

    If $bIgnoreCaps Then
        $sRegExp &= "|[A-Z]"
    Else
        $sText = StringLower($sText)
    EndIf

    If StringRegExp($sText, $sRegExp) Then ; exceptions may be case sensitive, or include abbreviations
        $bExceptions = True
        Local $aArray = StringRegExp($sText, "\A\S+|(\s+\S+)|\s+\z", 3), _ ; find any WS characters followed by any none WS characters
        $aSubs = _GetMultiSubs($sText, 1)
        If @error Then Return SetError(2, 0, $sText) ; no suitable delimiter available

        For $i = 0 To UBound($aArray) -1
            $aArray[$i] = StringStripWS($aArray[$i], 1)
            If Not StringInStr($sNewStr, $aSubs[0] & $aArray[$i], 1) Then $sNewStr &= $aSubs[0] & $aArray[$i] ; get unique exceptions
        Next
        $aArray = StringSplit($sNewStr, $aSubs[0], 3) ; overwrite the original array with an array of unique matches
        $aArray[0] = UBound($aArray) -1 ; get the number of unique matches

        _ArraySortByLen($aArray, 1, 1) ; reverse order the elements by length.
        If @error Then Return SetError(3, 0, $sText) ; failure to arrange by element length

        Local $aIgnore[UBound($aArray) -1], $iCount = 0
        ; don't touch - web stuff, or words containing underscore, capitals or numbers
        For $i = 1 To $aArray[0]
            If StringRegExp($aArray[$i], $sRegExp) Then
                $aIgnore[$iCount] = $aArray[$i] ; string to replace
                $iCount += 1
            EndIf
        Next
        $aArray = 0 ; no longer needed

        ReDim $aIgnore[$iCount]

        $aSubs = _GetMultiSubs($sText, $iCount)
        If @error Then Return SetError(2, 0, "") ; insufficient substitutes strings available
        For $i = 0 To $iCount -1
            $aSubs[$i] = " " & $aSubs[$i] & " " ; add padding to the replacements
            $sText = StringReplace($sText, $aIgnore[$i], $aSubs[$i], 0, 1) ; replace all the exceptions
        Next
    EndIf

    Local $CapsNext = 1, $sHyphens =  ChrW(8211) & ChrW(8212) & ChrW(173) & "-'" ; en dash, em dash, soft hyphen, hyphen and apostrophe
    $sNewStr = ""

    For $i = 1 To StringLen($sText) ; modified code from JCHD
        $sCurrChar = StringMid($sText, $i, 1)
        If StringIsAlpha($sCurrChar) Then
            If $CapsNext Then
                $sCurrChar = StringUpper($sCurrChar)
                $CapsNext = 0
            EndIf
        ElseIf StringInStr($sHyphens, $sCurrChar) Then ; changes to the original - hyphenation and apostrophe
            $CapsNext = 0
        Else
            $CapsNext = 1
        EndIf
        $sNewStr &= $sCurrChar
    Next

    If $bAP_Exceptions Then
        Local $aConj[24] = _
        ["A","An","And","As","At","But","By","For", _
        "From","In","Into","Nor","Of","On","Onto","Or", _
        "Per","So","The","To","Up","Via","With","Yet"]

        For $i = 0 To 23
            $sNewStr = StringReplace($sNewStr, " " & $aConj[$i] & " ", " " & StringLower($aConj[$i]) & " ")
            $sNewStr = StringReplace($sNewStr, "(" & $aConj[$i] & " ", "(" & StringLower($aConj[$i]) & " ")
            $sNewStr = StringReplace($sNewStr, " " & $aConj[$i] & ")", " " & StringLower($aConj[$i]) & ")")
        Next
    EndIf

    If $bInternational Then
        Local $aPartName[20] = _
        [" Af "," Av "," Da "," De "," Del "," Der "," Di ", _
        " E "," En "," Et "," Het "," La "," Las "," Lo ", _
        " Los "," Und "," Van De "," Van Der "," Von "," Y "]
        For $i = 0 To 19
            $sNewStr = StringReplace($sNewStr, $aPartName[$i], StringLower($aPartName[$i]))
        Next
    EndIf

    If $bExceptions Then
        For $i = $iCount -1 To 0 Step -1
            ; put all the exceptions back in the new string
            $sNewStr = StringReplace($sNewStr, $aSubs[$i], $aIgnore[$i])
        Next
    EndIf

    $sNewStr = $sWSLeft & $sNewStr & $sWSRight
    Return $sNewStr
EndFunc ;==> _TitleCase()

Func _GetMultiSubs($sTest, $iSubs)
    If Not IsString($sTest) Then Return SetError(1, 0, 0) ; Invalid Input String.
    If Not IsInt($iSubs) Or $iSubs < 1 Then Return SetError(2, 0, 0) ; Invalid number of substitute strings

    ; NOTE: The returned order of substitutes may be important.
    ; Extra padding may be needed to avoid substitutes coming into contact with other control characters.
    Local $aSubs[$iSubs], $aAscII[31], $iCount = 0, $sChar ; Using Control Characters only.

    ; First try one character
    For $i = 1 To 31
        $sChar = Chr($i)
        If Not StringInStr($sTest, $sChar, 1) Then
            $aSubs[$iCount] = $sChar
            $iCount +=1
            If $iCount = $iSubs Then Return $aSubs
        EndIf
        $aAscII[$i - 1] = $sChar ; Needed for the next stage.
    Next

    ; That failed - so we try two characters.
    Local $aDoubleChar = _ArrayCombinations($aAscII, 2, "")
    For $i = 1 To $aDoubleChar[0]
        $sChar = $aDoubleChar[$i]
        If Not StringInStr($sTest, $sChar, 1) Then
            $aSubs[$iCount] = $sChar
            $iCount +=1
            If $iCount = $iSubs Then Return $aSubs
        EndIf
    Next

    ; That failed - so we try the reverse patterns.
    ReDim $aDoubleChar[931]
    $aDoubleChar[0] = 930

    For $i = 466 To $aDoubleChar[0]
        $sChar = _StringReverse($aDoubleChar[$i -465])
        If Not StringInStr($sTest, $sChar, 1) Then
            $aSubs[$iCount] = $sChar
            $iCount +=1
            If $iCount = $iSubs Then Return $aSubs
        EndIf
        $aDoubleChar[$i] = $sChar ; Needed for the next stage.
    Next

    ; That failed - so we try three characters.
    For $i = 1 To $aDoubleChar[0]
        For $j = 0 To 30
            $sChar = $aDoubleChar[$i] & $aAscII[$j]
            If Not StringInStr($sTest, $sChar, 1) Then
                $aSubs[$iCount] = $sChar
                $iCount +=1
                If $iCount = $iSubs Then Return $aSubs
            EndIf
        Next
    Next

    ; That failed - so we try four characters.
    For $i = 1 To $aDoubleChar[0]
        For $j = 1 To $aDoubleChar[0]
            $sChar = $aDoubleChar[$i] & $aDoubleChar[$j]
            If Not StringInStr($sTest, $sChar, 1) Then
                $aSubs[$iCount] = $sChar
                $iCount +=1
                If $iCount = $iSubs Then Return $aSubs
            EndIf
        Next
    Next

    ; That failed - so we try five characters.
    For $i = 1 To $aDoubleChar[0]
        For $j = 1 To $aDoubleChar[0]
            For $k = 0 To 30
                $sChar = $aDoubleChar[$i] & $aDoubleChar[$j] & $aAscII[$k]
                If Not StringInStr($sTest, $sChar, 1) Then
                    $aSubs[$iCount] = $sChar
                    $iCount +=1
                    If $iCount = $iSubs Then Return $aSubs
                EndIf
            Next
        Next
    Next

    Return SetError (2, 0, "") ; Not enough substitutions available
EndFunc ; _GetMultiSubs()

Func _ArraySortByLen(ByRef $aArray, $iDescending =0, $iStart =0, $iEnd =0)
    If Not IsArray($aArray) Or UBound($aArray, 0) > 1 Then Return SetError(1, 0, 0) ; Not a 1D array
    If Not IsInt($iStart) Or Not IsInt($iEnd) Then Return SetError(5, 0, 0) ; Parameters need to be integers.

    Local $iBound = UBound($aArray)
    Local $aElementLen[$iBound][2]
    $iBound -=1

    For $i = 0 To $iBound
        $aElementLen[$i][0] = StringLen($aArray[$i]) ; Get the length of the element
        $aElementLen[$i][1] = $aArray[$i] ; The element to sort
    Next

    _ArraySort($aElementLen, $iDescending, $iStart, $iEnd)
    If @error Then Return SetError(@error, 0, 0) ; See _ArraySort() for error codes 2 to 4.

    For $i = 0 To $iBound
        $aArray[$i] = $aElementLen[$i][1]
    Next
    Return 1
EndFunc ;==> _ArraySortByLen()

See also:

Edit

Code Updated

Edited by czardas
Link to comment
Share on other sites

Changes to the above code

Added (optional) common British English (Associated Press) lower case exceptions.

Added (optional) minimal support for international names which may sometimes appear in English Titles.

Edit

New parameter options added: ==> Documentation still needs updating. You can try out the different parameters to see what difference they make ($bAP_Exceptions = Associated Press lower case exceptions). I do not intend to add any extra functionality to this. It is what it is.

Edited by czardas
Link to comment
Share on other sites

  • 1 month later...

Above posts still need a few cobwebs removing.

:whistle:

XORSplit and ORSplit

Randomly split an integer into two bitwise exclusive (or non-exclusive) integers which can be bitwise-OR'ed together to produce the original value.

_Examples()

Func _Examples()
    Local $iInteger = 123456789

    Local $aExample1 = XORSplit($iInteger) ; Returns a two element array - see comments below.
    ; Check the results are correct:
    ConsoleWrite("XORSplit (" & $iInteger & ")" & @LF)
    ConsoleWrite("BitOR(" & $aExample1[0] & ", " & $aExample1[1] & ") = " & _
    BitOR($aExample1[0], $aExample1[1]) & @LF & @LF) ; Values can be Bitwise-OR'ed together.

    Local $aExample2 = ORSplit($iInteger) ; Returns a two element array - see comments below.
    ; Check the results are correct:
    ConsoleWrite("ORSplit (" & $iInteger & ")" & @LF)
    ConsoleWrite("BitOR(" & $aExample2[0] & ", " & $aExample2[1] & ") = " & _
    BitOR($aExample2[0], $aExample2[1]) & @LF & @LF) ; Values can be Bitwise-OR'ed together.
EndFunc

Func XORSplit($i32Bit) ; Splits an integer into two randomly selected bitwise exclusive integers.
    If Not IsInt($i32Bit) Or $i32Bit >= 2^32 Or $i32Bit < 0x80000000 Then Return SetError(1, 0, 0)

    Local $aXOR[2]
    $aXOR[0] = 0
    ; Randomly select which bits to reproduce in the first return value. => $aXOR[0]
    Local $iBitPos
    For $i = 0 To 31
        $iBitPos = 2^$i
        If BitAND($i32Bit, $iBitPos) = $iBitPos And Random(0, 1, 1) Then $aXOR[0] = BitOR($aXOR[0], $iBitPos)
    Next
    ; Check the sign bit.
    If BitAND($i32Bit, 0x80000000) = 0x80000000 And Random(0, 1, 1) Then $aXOR[0] = BitOR($aXOR[0], 0x80000000)

    ; Exclude the bits set to one (in the first return value) from the original input.
    $aXOR[1] = BitXOR($i32Bit, $aXOR[0])
    Return $aXOR ; Array values can be Bitwise-OR'ed together to reproduce the original input.
EndFunc ;==> XORSplit

Func ORSplit($i32Bit) ; Splits an integer into two randomly selected bitwise non-exclusive integers.
    If Not IsInt($i32Bit) Or $i32Bit >= 2^32 Or $i32Bit < 0x80000000 Then Return SetError(1, 0, 0)

    Local $aOR[2]
    $aOR[0] = 0
    $aOR[1] = 0

    ; Randomly select which bits to reproduce in either one or both return values.
    Local $iBitPos, $iSwitch = Random(1,3,1)
    For $i = 0 To 31
        $iBitPos = 2^$i
        If BitAND($i32Bit, $iBitPos) = $iBitPos Then
            For $n = 1 To 2
                If BitAND($iSwitch, $n) = $n Then $aOR[$n -1] = BitOR($aOR[$n -1], $iBitPos)
            Next
            $iSwitch = Random(1,3,1) ; Set the switch for the next run.
        EndIf
    Next

    ; Check the sign bit.
    If BitAND($i32Bit, 0x80000000) = 0x80000000 Then
        For $n = 1 To 2
            If BitAND($iSwitch, $n) = $n Then $aOR[$n -1] = BitOR($aOR[$n -1], 0x80000000)
        Next
    EndIf

    Return $aOR ; Array values can be Bitwise-OR'ed together to reproduce the original input.
EndFunc ;==> ORSplit
Edited by czardas
Link to comment
Share on other sites

Ideally ORSplit should be able to return up to 255 values to be consistant with other bitwise functions in AutoIt. With XORSplit however, 255 return values would be impossible, since there are only 32 available bit positions. Needs more thought! Anyway, let me know if you think of any uses for these functions. I have only thought of one concrete scenario, but I bet there will be possibilities I haven't considered.

Edited by czardas
Link to comment
Share on other sites

  • 3 weeks later...

Loch Ness Monster Case and Camel Case

Some sightings of Loch Ness Monster Case have been reported in the wild, although none have been substantiated. Also note that Camel Case isn't normally found outside its native enviroment. ^^

#include-once
#include <Array.au3>

MsgBox(0, LochNessMonsterCase("message from nessie"), LochNessMonsterCase("hello from the loch ness monster!"))

Func LochNessMonsterCase($sText)
    If StringRegExp($sText, "(?i)[[:alpha:]]") = 0 Then Return SetError(1, 0, $sText) ; Contains no alpha characters.

    Local $aWords = StringRegExp($sText, "(?i)[[:alpha:]']+", 3)
    $aWords = _ArrayUnique($aWords)
    _ArraySortByLen($aWords, 0, 1)

    Local $iLen, $iMidPoint, $sCurrChar, $sTempStr, $iApostrophe
    For $i = 1 To $aWords[0]
        $iApostrophe = StringInStr($aWords[$i], "'")
        If $iApostrophe Then $aWords[$i] = StringReplace($aWords[$i], "'", "", 1)

        $iLen = StringLen($aWords[$i])
        $iMidPoint = Ceiling($iLen/2)
        If Mod($iLen , 2) = 0 Then $iMidPoint += 1

        $sTempStr = ""
        For $j = 1 To $iLen
            $sCurrChar = StringMid($aWords[$i], $j, 1)
            If $j = $iMidPoint Or $j = $iMidPoint -1 Then
                $sCurrChar = StringUpper($sCurrChar)
            Else
                $sCurrChar = StringLower($sCurrChar)
            EndIf
            $sTempStr &= $sCurrChar
        Next

        If $iApostrophe Then $sTempStr = StringLeft($sTempStr, $iApostrophe -1) & "'" & StringRight($sTempStr, $iLen -$iApostrophe +1)
        $sText = StringReplace($sText, $sTempStr, $sTempStr)
    Next

    Return $sText
EndFunc ;==> LochNessMonsterCase

Func _ArraySortByLen(ByRef $aArray, $iDescending =0, $iStart =0, $iEnd =0)
    If Not IsArray($aArray) Or UBound($aArray, 0) > 1 Then Return SetError(1, 0, 0) ; Not a 1D array
    If Not IsInt($iStart) Or Not IsInt($iEnd) Then Return SetError(5, 0, 0) ; Parameters need to be integers.

    Local $iBound = UBound($aArray)
    Local $aElementLen[$iBound][2]
    $iBound -=1

    For $i = 0 To $iBound
        $aElementLen[$i][0] = StringLen($aArray[$i]) ; Get the length of the element
        $aElementLen[$i][1] = $aArray[$i] ; The element to sort
    Next

    _ArraySort($aElementLen, $iDescending, $iStart, $iEnd)
    If @error Then Return SetError(@error, 0, 0) ; See _ArraySort() for error codes 2 to 4.

    For $i = 0 To $iBound
        $aArray[$i] = $aElementLen[$i][1]
    Next
    Return 1
EndFunc ;==> _ArraySortByLen

MsgBox(0, "Camel Case", CamelCase("  _ testing _ camel _  case" & @TAB & "   ThIs caMeL hAs 3 hUMPS  "))

Func CamelCase($sText, $CapsNext = 1, $bRecursion = False)
    If StringLen($sText) = 0 Then Return SetError(1)
    If Not $bRecursion Then $sText = StringLower($sText)

    Local $sNewStr = "", $sCurrChar
    For $i = 1 To StringLen($sText)
        $sCurrChar = StringMid($sText, $i, 1)
        If StringRegExp($sCurrChar, "\w") Then
            If Not $bRecursion Then
                If StringIsAlpha($sCurrChar) Then
                     If $CapsNext Then
                        $sCurrChar = StringUpper($sCurrChar)
                        $CapsNext = 0
                    EndIf
                Else
                    $CapsNext = 1
                EndIf
            Else
                If StringIsAlpha($sCurrChar) And Not $CapsNext Then
                    $sCurrChar = StringLower($sCurrChar)
                    $CapsNext = 1
                EndIf
            EndIf

        ElseIf $bRecursion Then
            $CapsNext = 0
        Else
            $CapsNext = 1
        EndIf
        $sNewStr &= $sCurrChar
    Next

    If Not $bRecursion Then
        While StringRegExp($sNewStr, "(\w)( +)(\w)")
            $sNewStr = StringRegExpReplace($sNewStr, "(\w)( +)(\w)", "\1\3")
        WEnd
        $sNewStr = CamelCase($sNewStr, 0, True)
    EndIf

    Return $sNewStr
EndFunc ;==> CamelCase
Edited by czardas
Link to comment
Share on other sites

IT apPEars lOCh nESs moNSter cASe dOEs eXIst: https://gist.github.com/gotmayonase/1996344

eDIt OH MY GOd. HOw embaRRasing. I couLDn't undeRStand tHIs AT fIRst. I remEMber somEThing aBOut tHEre bEIng A lOCh nESs moNSter cASe, BUt I couLDn't remEMber THe rULes. I cOUld oNLy fINd THe ONe lINk.

NOw aLSo wORks wITh wORds contAIning A siNGle aposTRophe.


Camel Case does what I believe it ought to do. The conversion to Camel Case is intended to opperate on word characters only (alphanumeric chars and underscore). Spaces are stripped between all word characters, and any other characters trigger a new instance of Camel Case. Non-word characters (with the exception of space) may therefore be used to separate multiple conversions. :think:

Note: You should only pass one parameter to this function.

Edited by czardas
Link to comment
Share on other sites

_StringIsNumber

The functions StringIsInt() and StringIsFloat() only cover two types of numeric notation. In my opinion StringIsFloat() ought to return 1 for scientific notation, but it doesn't. Likewise StringIsInt() returns 0 for (within bounds integers using) hexadecimal notation. There is no general test to see whether a string contains some form of number recognised by the AutoIt interpreter.

#region - Examples
MsgBox(0, "Integer", "_StringIsNumber(900)" & @LF & "  Returns ==> " & _
    _StringIsNumber("900"))
MsgBox(0, "Float", "_StringIsNumber(0.7)" & @LF & "  Returns ==> " & _
    _StringIsNumber("0.7"))
MsgBox(0, "32Bit Integer", "_StringIsNumber(+0xF)" & @LF & "  Returns ==> " & _
    _StringIsNumber("+0xF"))
MsgBox(0, "Exponential", "_StringIsNumber(-0.8e-200)" & @LF & "  Returns ==> " & _
    _StringIsNumber("-0.8e-200"))
MsgBox(0, "Vulgar Fraction", "_StringIsNumber(7/12, True)" & @LF & "  Returns ==> " & _
    _StringIsNumber("7/12", True))
MsgBox(0, "Random String", "_StringIsNumber(Random String)" & @LF & "  Returns ==> " & _
    _StringIsNumber("Random String"))
#endregion

Func _StringIsNumber($sString, $bVulgarFrac = False)
    Local $bReturn = False

    If StringIsInt($sString) Or StringIsFloat($sString) Then
        $bReturn = True ; string is integer or float

    ElseIf StringRegExp($sString, "(?i)(\A[\+\-]?0x[A-F\d]+\z)") Then
        $bReturn = True ; string is hexadecimal integer

    ElseIf StringRegExp($sString, "(?i)(\A[\+\-]?\d*\.?\d+e[\+\-]?\d+\z)") Then
        $bReturn = True ; exponential (or scientific notation)

    ElseIf $bVulgarFrac And StringRegExp($sString, "(\A[\+\-]?\d+/\d+\z)") Then
        $bReturn = True ; string is a vulgar fraction
    EndIf

    Return $bReturn
EndFunc

To the interpreter, vulgar fractions such as -3/4 constitute an expression which evaluates to a number (-0.75). _StringIsNumber() will only recognise vulgar fractions if you override the default value for the second parameter - see the example above.

Edited by czardas
Link to comment
Share on other sites

_ArraySortByNumber

An example of use for the above function - sorting a one dimensional array (ascending) first by number, followed by strings in alphabetical order.

#include <Array.au3>

Local $aTest[16] = ["55","3ABC","-12e+020",6.4,"399","0x0F","2.1e-115","-3","2,0xopo","1/3","C2","False","12b","0x80000000","E0","0"]
_ArrayDisplay($aTest, "Before Sorting")

_ArraySortByNumber($aTest, True)
_ArrayDisplay($aTest, "After Sorting")

Func _ArraySortByNumber(ByRef $aArray, $bVulgarFrac = False)
    If Not IsArray($aArray) Or UBound($aArray, 0) > 1 Then Return SetError(1, 0, 0)

    Local $iBound = UBound($aArray)
    Local $aTemp[$iBound][2], $iCount = 0

    For $i = 0 To $iBound -1
        $aTemp[$i][0] = $aArray[$i]
        If _StringIsNumber($aArray[$i], $bVulgarFrac) Then
            $aTemp[$i][1] = Execute($aArray[$i])
            $iCount += 1
        Else
            $aTemp[$i][1] = "z" & $aArray[$i]
        EndIf
    Next
    _ArraySort($aTemp, 0, 0, 0, 1)

    For $i = 0 To $iBound -1
        $aArray[$i] = $aTemp[$i][0]
    Next
EndFunc

Func _StringIsNumber($sString, $bVulgarFrac = False)
    Local $bReturn = False

    If StringIsInt($sString) Or StringIsFloat($sString) Then
        $bReturn = True ; string is integer or float

    ElseIf StringRegExp($sString, "(?i)(\A[\+\-]?0x[A-F\d]+\z)") Then
        $bReturn = True ; string is hexadecimal integer

    ElseIf StringRegExp($sString, "(?i)(\A[\+\-]?\d*\.?\d+e[\+\-]?\d+\z)") Then
        $bReturn = True ; exponential (or scientific notation)

    ElseIf $bVulgarFrac And StringRegExp($sString, "(\A[\+\-]?\d+/\d+\z)") Then
        $bReturn = True ; string is a vulgar fraction
    EndIf

    Return $bReturn
EndFunc

Edit

Fixed a leak in _StringIsNumber(). It's better now.

Edited by czardas
Link to comment
Share on other sites

_StripPunctuation

Remove (or replace) all punctuation from any language (limited to UCS-2). Credit and appreciation, to JCHD and trancexx, for spending time helping me to understand more about unicode.

Func _StripPunctuation($sText, $sReplaceWith = "")
    If Not IsString($sText) Then Return SetError(1, 0, "") ; invalid first parameter
    If Not IsString($sReplaceWith) Then Return SetError(2, 0, "") ; invalid second parameter

    $sText = StringRegExpReplace($sText, "[" & _
    "\x{0021}\x{0022}\x{0023}\x{0025}\x{0026}\x{0027}\x{0028}\x{0029}\x{002A}\x{002C}\x{002D}\x{002E}\x{002F}\x{003A}\x{003B}" & _
    "\x{003F}\x{0040}\x{005B}\x{005C}\x{005D}\x{005F}\x{007B}\x{007D}\x{00A1}\x{00A7}\x{00AB}\x{00B6}\x{00B7}\x{00BB}\x{00BF}" & _
    "\x{037E}\x{0387}\x{055A}\x{055B}\x{055C}\x{055D}\x{055E}\x{055F}\x{0589}\x{058A}\x{05BE}\x{05C0}\x{05C3}\x{05C6}\x{05F3}" & _
    "\x{05F4}\x{0609}\x{060A}\x{060C}\x{060D}\x{061B}\x{061E}\x{061F}\x{066A}\x{066B}\x{066C}\x{066D}\x{06D4}\x{0700}\x{0701}" & _
    "\x{0702}\x{0703}\x{0704}\x{0705}\x{0706}\x{0707}\x{0708}\x{0709}\x{070A}\x{070B}\x{070C}\x{070D}\x{07F7}\x{07F8}\x{07F9}" & _
    "\x{0830}\x{0831}\x{0832}\x{0833}\x{0834}\x{0835}\x{0836}\x{0837}\x{0838}\x{0839}\x{083A}\x{083B}\x{083C}\x{083D}\x{083E}" & _
    "\x{085E}\x{0964}\x{0965}\x{0970}\x{0AF0}\x{0DF4}\x{0E4F}\x{0E5A}\x{0E5B}\x{0F04}\x{0F05}\x{0F06}\x{0F07}\x{0F08}\x{0F09}" & _
    "\x{0F0A}\x{0F0B}\x{0F0C}\x{0F0D}\x{0F0E}\x{0F0F}\x{0F10}\x{0F11}\x{0F12}\x{0F14}\x{0F3A}\x{0F3B}\x{0F3C}\x{0F3D}\x{0F85}" & _
    "\x{0FD0}\x{0FD1}\x{0FD2}\x{0FD3}\x{0FD4}\x{0FD9}\x{0FDA}\x{104A}\x{104B}\x{104C}\x{104D}\x{104E}\x{104F}\x{10FB}\x{1360}" & _
    "\x{1361}\x{1362}\x{1363}\x{1364}\x{1365}\x{1366}\x{1367}\x{1368}\x{1400}\x{166D}\x{166E}\x{169B}\x{169C}\x{16EB}\x{16EC}" & _
    "\x{16ED}\x{1735}\x{1736}\x{17D4}\x{17D5}\x{17D6}\x{17D8}\x{17D9}\x{17DA}\x{1800}\x{1801}\x{1802}\x{1803}\x{1804}\x{1805}" & _
    "\x{1806}\x{1807}\x{1808}\x{1809}\x{180A}\x{1944}\x{1945}\x{1A1E}\x{1A1F}\x{1AA0}\x{1AA1}\x{1AA2}\x{1AA3}\x{1AA4}\x{1AA5}" & _
    "\x{1AA6}\x{1AA8}\x{1AA9}\x{1AAA}\x{1AAB}\x{1AAC}\x{1AAD}\x{1B5A}\x{1B5B}\x{1B5C}\x{1B5D}\x{1B5E}\x{1B5F}\x{1B60}\x{1BFC}" & _
    "\x{1BFD}\x{1BFE}\x{1BFF}\x{1C3B}\x{1C3C}\x{1C3D}\x{1C3E}\x{1C3F}\x{1C7E}\x{1C7F}\x{1CC0}\x{1CC1}\x{1CC2}\x{1CC3}\x{1CC4}" & _
    "\x{1CC5}\x{1CC6}\x{1CC7}\x{1CD3}\x{2010}\x{2011}\x{2012}\x{2013}\x{2014}\x{2015}\x{2016}\x{2017}\x{2018}\x{2019}\x{201A}" & _
    "\x{201B}\x{201C}\x{201D}\x{201E}\x{201F}\x{2020}\x{2021}\x{2022}\x{2023}\x{2024}\x{2025}\x{2026}\x{2027}\x{2030}\x{2031}" & _
    "\x{2032}\x{2033}\x{2034}\x{2035}\x{2036}\x{2037}\x{2038}\x{2039}\x{203A}\x{203B}\x{203C}\x{203D}\x{203E}\x{203F}\x{2040}" & _
    "\x{2041}\x{2042}\x{2043}\x{2045}\x{2046}\x{2047}\x{2048}\x{2049}\x{204A}\x{204B}\x{204C}\x{204D}\x{204E}\x{204F}\x{2050}" & _
    "\x{2051}\x{2053}\x{2054}\x{2055}\x{2056}\x{2057}\x{2058}\x{2059}\x{205A}\x{205B}\x{205C}\x{205D}\x{205E}\x{207D}\x{207E}" & _
    "\x{208D}\x{208E}\x{2329}\x{232A}\x{2768}\x{2769}\x{276A}\x{276B}\x{276C}\x{276D}\x{276E}\x{276F}\x{2770}\x{2771}\x{2772}" & _
    "\x{2773}\x{2774}\x{2775}\x{27C5}\x{27C6}\x{27E6}\x{27E7}\x{27E8}\x{27E9}\x{27EA}\x{27EB}\x{27EC}\x{27ED}\x{27EE}\x{27EF}" & _
    "\x{2983}\x{2984}\x{2985}\x{2986}\x{2987}\x{2988}\x{2989}\x{298A}\x{298B}\x{298C}\x{298D}\x{298E}\x{298F}\x{2990}\x{2991}" & _
    "\x{2992}\x{2993}\x{2994}\x{2995}\x{2996}\x{2997}\x{2998}\x{29D8}\x{29D9}\x{29DA}\x{29DB}\x{29FC}\x{29FD}\x{2CF9}\x{2CFA}" & _
    "\x{2CFB}\x{2CFC}\x{2CFE}\x{2CFF}\x{2D70}\x{2E00}\x{2E01}\x{2E02}\x{2E03}\x{2E04}\x{2E05}\x{2E06}\x{2E07}\x{2E08}\x{2E09}" & _
    "\x{2E0A}\x{2E0B}\x{2E0C}\x{2E0D}\x{2E0E}\x{2E0F}\x{2E10}\x{2E11}\x{2E12}\x{2E13}\x{2E14}\x{2E15}\x{2E16}\x{2E17}\x{2E18}" & _
    "\x{2E19}\x{2E1A}\x{2E1B}\x{2E1C}\x{2E1D}\x{2E1E}\x{2E1F}\x{2E20}\x{2E21}\x{2E22}\x{2E23}\x{2E24}\x{2E25}\x{2E26}\x{2E27}" & _
    "\x{2E28}\x{2E29}\x{2E2A}\x{2E2B}\x{2E2C}\x{2E2D}\x{2E2E}\x{2E30}\x{2E31}\x{2E32}\x{2E33}\x{2E34}\x{2E35}\x{2E36}\x{2E37}" & _
    "\x{2E38}\x{2E39}\x{2E3A}\x{2E3B}\x{3001}\x{3002}\x{3003}\x{3008}\x{3009}\x{300A}\x{300B}\x{300C}\x{300D}\x{300E}\x{300F}" & _
    "\x{3010}\x{3011}\x{3014}\x{3015}\x{3016}\x{3017}\x{3018}\x{3019}\x{301A}\x{301B}\x{301C}\x{301D}\x{301E}\x{301F}\x{3030}" & _
    "\x{303D}\x{30A0}\x{30FB}\x{A4FE}\x{A4FF}\x{A60D}\x{A60E}\x{A60F}\x{A673}\x{A67E}\x{A6F2}\x{A6F3}\x{A6F4}\x{A6F5}\x{A6F6}" & _
    "\x{A6F7}\x{A874}\x{A875}\x{A876}\x{A877}\x{A8CE}\x{A8CF}\x{A8F8}\x{A8F9}\x{A8FA}\x{A92E}\x{A92F}\x{A95F}\x{A9C1}\x{A9C2}" & _
    "\x{A9C3}\x{A9C4}\x{A9C5}\x{A9C6}\x{A9C7}\x{A9C8}\x{A9C9}\x{A9CA}\x{A9CB}\x{A9CC}\x{A9CD}\x{A9DE}\x{A9DF}\x{AA5C}\x{AA5D}" & _
    "\x{AA5E}\x{AA5F}\x{AADE}\x{AADF}\x{AAF0}\x{AAF1}\x{ABEB}\x{FD3E}\x{FD3F}\x{FE10}\x{FE11}\x{FE12}\x{FE13}\x{FE14}\x{FE15}" & _
    "\x{FE16}\x{FE17}\x{FE18}\x{FE19}\x{FE30}\x{FE31}\x{FE32}\x{FE33}\x{FE34}\x{FE35}\x{FE36}\x{FE37}\x{FE38}\x{FE39}\x{FE3A}" & _
    "\x{FE3B}\x{FE3C}\x{FE3D}\x{FE3E}\x{FE3F}\x{FE40}\x{FE41}\x{FE42}\x{FE43}\x{FE44}\x{FE45}\x{FE46}\x{FE47}\x{FE48}\x{FE49}" & _
    "\x{FE4A}\x{FE4B}\x{FE4C}\x{FE4D}\x{FE4E}\x{FE4F}\x{FE50}\x{FE51}\x{FE52}\x{FE54}\x{FE55}\x{FE56}\x{FE57}\x{FE58}\x{FE59}" & _
    "\x{FE5A}\x{FE5B}\x{FE5C}\x{FE5D}\x{FE5E}\x{FE5F}\x{FE60}\x{FE61}\x{FE63}\x{FE68}\x{FE6A}\x{FE6B}\x{FF01}\x{FF02}\x{FF03}" & _
    "\x{FF05}\x{FF06}\x{FF07}\x{FF08}\x{FF09}\x{FF0A}\x{FF0C}\x{FF0D}\x{FF0E}\x{FF0F}\x{FF1A}\x{FF1B}\x{FF1F}\x{FF20}\x{FF3B}" & _
    "\x{FF3C}\x{FF3D}\x{FF3F}\x{FF5B}\x{FF5D}\x{FF5F}\x{FF60}\x{FF61}\x{FF62}\x{FF63}\x{FF64}\x{FF65}]", $sReplaceWith)
    Return $sText
EndFunc ;==> _StripPunctuation
Edited by czardas
Link to comment
Share on other sites

Updates And Improvements

This post is reserved for logging updates or any changes to code in previous posts. For me this represents a period of reflection. I made some half-hearted attempts to solve some problems, and this needs redressing.

Post #49 (30/03/2013)

Implemented a much more aggressive approach - see post #49 for details.

The above function was renamed. (30/03/2013)

Edited by czardas
Link to comment
Share on other sites

Looking at the code, I believe it has the same issue that is exposed in

Also looking further, I find a lot of discrepancies with what was categorized as "any Punctuation" by the 5.1 Unicode standard.

Here's a brief comparison, my version as comments. I've shifted values here and there to align equal values.

Func _StripPunctuation($sText, $sReplaceWith = "")
    If Not IsString($sText) Then Return SetError(1, 0, $sText) ; invalid first parameter
    If Not (IsString($sReplaceWith) Or IsNumber($sReplaceWith)) Then Return SetError(2, 0, $sText) ; invalid second parameter

    $sText = StringRegExpReplace($sText, "[" & _
;\x{0021}\x{0022}\x{0023}\x{0025}\x{0026}\x{0027}\x{0028}\x{0029}\x{002A}\x{002C}\x{002D}\x{002E}\x{002F}\x{003A}\x{003B}
"\x{0021}\x{0022}\x{0023}\x{0025}\x{0026}\x{0027}\x{0028}\x{0029}\x{002A}\x{002C}\x{002D}\x{002E}\x{002F}\x{003A}\x{003B}" & _

;\x{003F}\x{0040}\x{005B}\x{005C}\x{005D}\x{005F}\x{007B}\x{007D}\x{00A1}       \x{00AB}        \x{00B7}\x{00BB}\x{00BF}
"\x{003F}\x{0040}\x{005B}\x{005C}\x{005D}\x{005F}\x{007B}\x{007D}\x{00A1}\x{00A7}\x{00AB}\x{00B6}\x{00B7}\x{00BB}\x{00BF}" & _

;\x{037E}\x{0387}\x{055A}\x{055B}\x{055C}\x{055D}\x{055E}\x{055F}\x{0589}\x{058A}\x{05BE}\x{05C0}\x{05C3}\x{05C6}\x{05F3}
"\x{037E}\x{0387}\x{055A}\x{055B}\x{055C}\x{055D}\x{055E}\x{055F}\x{0589}\x{058A}\x{05BE}\x{05C0}\x{05C3}\x{05C6}\x{05F3}" & _

;\x{05F4}\x{0609}\x{060A}\x{060C}\x{060D}\x{061B}\x{061E}\x{061F}\x{066A}\x{066B}\x{066C}\x{066D}\x{06D4}\x{0700}\x{0701}
"\x{05F4}\x{0609}\x{060A}\x{060C}\x{060D}\x{061B}\x{061E}\x{061F}\x{066A}\x{066B}\x{066C}\x{066D}\x{06D4}\x{0700}\x{0701}" & _

;\x{0702}\x{0703}\x{0704}\x{0705}\x{0706}\x{0707}\x{0708}\x{0709}\x{070A}\x{070B}\x{070C}\x{070D}\x{07F7}\x{07F8}\x{07F9}
"\x{0702}\x{0703}\x{0704}\x{0705}\x{0706}\x{0707}\x{0708}\x{0709}\x{070A}\x{070B}\x{070C}\x{070D}\x{07F7}\x{07F8}\x{07F9}" & _

;
"\x{0830}\x{0831}\x{0832}\x{0833}\x{0834}\x{0835}\x{0836}\x{0837}\x{0838}\x{0839}\x{083A}\x{083B}\x{083C}\x{083D}\x{083E}" & _

;       \x{0964}\x{0965}\x{0970}        \x{0DF4}\x{0E4F}\x{0E5A}\x{0E5B}\x{0F04}\x{0F05}\x{0F06}\x{0F07}\x{0F08}\x{0F09}
"\x{085E}\x{0964}\x{0965}\x{0970}\x{0AF0}\x{0DF4}\x{0E4F}\x{0E5A}\x{0E5B}\x{0F04}\x{0F05}\x{0F06}\x{0F07}\x{0F08}\x{0F09}" & _

;\x{0F0A}\x{0F0B}\x{0F0C}\x{0F0D}\x{0F0E}\x{0F0F}\x{0F10}\x{0F11}\x{0F12}       \x{0F3A}\x{0F3B}\x{0F3C}\x{0F3D}\x{0F85}
"\x{0F0A}\x{0F0B}\x{0F0C}\x{0F0D}\x{0F0E}\x{0F0F}\x{0F10}\x{0F11}\x{0F12}\x{0F14}\x{0F3A}\x{0F3B}\x{0F3C}\x{0F3D}\x{0F85}" & _

;\x{0FD0}\x{0FD1}\x{0FD2}\x{0FD3}\x{0FD4}               \x{104A}\x{104B}\x{104C}\x{104D}\x{104E}\x{104F}\x{10FB}
"\x{0FD0}\x{0FD1}\x{0FD2}\x{0FD3}\x{0FD4}\x{0FD9}\x{0FDA}\x{104A}\x{104B}\x{104C}\x{104D}\x{104E}\x{104F}\x{10FB}\x{1360}" & _

;\x{1361}\x{1362}\x{1363}\x{1364}\x{1365}\x{1366}\x{1367}\x{1368}       \x{166D}\x{166E}\x{169B}\x{169C}\x{16EB}\x{16EC}
"\x{1361}\x{1362}\x{1363}\x{1364}\x{1365}\x{1366}\x{1367}\x{1368}\x{1400}\x{166D}\x{166E}\x{169B}\x{169C}\x{16EB}\x{16EC}" & _

;\x{16ED}\x{1735}\x{1736}\x{17D4}\x{17D5}\x{17D6}\x{17D8}\x{17D9}\x{17DA}\x{1800}\x{1801}\x{1802}\x{1803}\x{1804}\x{1805}
"\x{16ED}\x{1735}\x{1736}\x{17D4}\x{17D5}\x{17D6}\x{17D8}\x{17D9}\x{17DA}\x{1800}\x{1801}\x{1802}\x{1803}\x{1804}\x{1805}" & _

;\x{1806}\x{1807}\x{1808}\x{1809}\x{180A}\x{1944}\x{1945}\x{19DE}\x{19DF}\x{1A1E}\x{1A1F}\x{1B5A}\x{1B5B}\x{1B5C}\x{1B5D}
"\x{1806}\x{1807}\x{1808}\x{1809}\x{180A}\x{1944}\x{1945}               \x{1A1E}\x{1A1F}

;
"\x{1AA0}\x{1AA1}\x{1AA2}\x{1AA3}\x{1AA4}\x{1AA5}\x{1AA6}\x{1AA8}\x{1AA9}\x{1AAA}\x{1AAB}\x{1AAC}\x{1AAD}\x{1B5A}\x{1B5B}" & _

;               \x{1B5E}\x{1B5F}\x{1B60}                                \x{1C3B}\x{1C3C}\x{1C3D}\x{1C3E}\x{1C3F}\x{1C7E}
"\x{1B5C}\x{1B5D}\x{1B5E}\x{1B5F}\x{1B60}\x{1BFC}\x{1BFD}\x{1BFE}\x{1BFF}\x{1C3B}\x{1C3C}\x{1C3D}\x{1C3E}\x{1C3F}\x{1C7E}" & _

;\x{1C7F}                                                                       \x{2010}\x{2011}\x{2012}\x{2013}\x{2014}
"\x{1C7F}\x{1CC0}\x{1CC1}\x{1CC2}\x{1CC3}\x{1CC4}\x{1CC5}\x{1CC6}\x{1CC7}\x{1CD3}\x{2010}\x{2011}\x{2012}\x{2013}\x{2014}" & _

;\x{2015}\x{2016}\x{2017}\x{2018}\x{2019}\x{201A}\x{201B}\x{201C}\x{201D}\x{201E}\x{201F}\x{2020}\x{2021}\x{2022}\x{2023}
"\x{2015}\x{2016}\x{2017}\x{2018}\x{2019}\x{201A}\x{201B}\x{201C}\x{201D}\x{201E}\x{201F}\x{2020}\x{2021}\x{2022}\x{2023}" & _

;\x{2024}\x{2025}\x{2026}\x{2027}\x{2030}\x{2031}\x{2032}\x{2033}\x{2034}\x{2035}\x{2036}\x{2037}\x{2038}\x{2039}\x{203A}
"\x{2024}\x{2025}\x{2026}\x{2027}\x{2030}\x{2031}\x{2032}\x{2033}\x{2034}\x{2035}\x{2036}\x{2037}\x{2038}\x{2039}\x{203A}" & _

;\x{203B}\x{203C}\x{203D}\x{203E}\x{203F}\x{2040}\x{2041}\x{2042}\x{2043}\x{2045}\x{2046}\x{2047}\x{2048}\x{2049}\x{204A}
"\x{203B}\x{203C}\x{203D}\x{203E}\x{203F}\x{2040}\x{2041}\x{2042}\x{2043}\x{2045}\x{2046}\x{2047}\x{2048}\x{2049}\x{204A}" & _

;\x{204B}\x{204C}\x{204D}\x{204E}\x{204F}\x{2050}\x{2051}\x{2053}\x{2054}\x{2055}\x{2056}\x{2057}\x{2058}\x{2059}\x{205A}
"\x{204B}\x{204C}\x{204D}\x{204E}\x{204F}\x{2050}\x{2051}\x{2053}\x{2054}\x{2055}\x{2056}\x{2057}\x{2058}\x{2059}\x{205A}" & _

;\x{205B}\x{205C}\x{205D}\x{205E}\x{207D}\x{207E}\x{208D}\x{208E}\x{2329}\x{232A}\x{2768}\x{2769}\x{276A}\x{276B}\x{276C}
"\x{205B}\x{205C}\x{205D}\x{205E}\x{207D}\x{207E}\x{208D}\x{208E}\x{2329}\x{232A}\x{2768}\x{2769}\x{276A}\x{276B}\x{276C}" & _

;\x{276D}\x{276E}\x{276F}\x{2770}\x{2771}\x{2772}\x{2773}\x{2774}\x{2775}\x{27C5}\x{27C6}\x{27E6}\x{27E7}\x{27E8}\x{27E9}
"\x{276D}\x{276E}\x{276F}\x{2770}\x{2771}\x{2772}\x{2773}\x{2774}\x{2775}\x{27C5}\x{27C6}\x{27E6}\x{27E7}\x{27E8}\x{27E9}" & _

;\x{27EA}\x{27EB}\x{27EC}\x{27ED}\x{27EE}\x{27EF}\x{2983}\x{2984}\x{2985}\x{2986}\x{2987}\x{2988}\x{2989}\x{298A}\x{298B}
"\x{27EA}\x{27EB}\x{27EC}\x{27ED}\x{27EE}\x{27EF}\x{2983}\x{2984}\x{2985}\x{2986}\x{2987}\x{2988}\x{2989}\x{298A}\x{298B}" & _

;\x{298C}\x{298D}\x{298E}\x{298F}\x{2990}\x{2991}\x{2992}\x{2993}\x{2994}\x{2995}\x{2996}\x{2997}\x{2998}\x{29D8}\x{29D9}
"\x{298C}\x{298D}\x{298E}\x{298F}\x{2990}\x{2991}\x{2992}\x{2993}\x{2994}\x{2995}\x{2996}\x{2997}\x{2998}\x{29D8}\x{29D9}" & _

;\x{29DA}\x{29DB}\x{29FC}\x{29FD}\x{2CF9}\x{2CFA}\x{2CFB}\x{2CFC}\x{2CFE}\x{2CFF}       \x{2E00}\x{2E01}\x{2E02}\x{2E03}
"\x{29DA}\x{29DB}\x{29FC}\x{29FD}\x{2CF9}\x{2CFA}\x{2CFB}\x{2CFC}\x{2CFE}\x{2CFF}\x{2D70}\x{2E00}\x{2E01}\x{2E02}\x{2E03}" & _

;\x{2E04}\x{2E05}\x{2E06}\x{2E07}\x{2E08}\x{2E09}\x{2E0A}\x{2E0B}\x{2E0C}\x{2E0D}\x{2E0E}\x{2E0F}\x{2E10}\x{2E11}\x{2E12}
"\x{2E04}\x{2E05}\x{2E06}\x{2E07}\x{2E08}\x{2E09}\x{2E0A}\x{2E0B}\x{2E0C}\x{2E0D}\x{2E0E}\x{2E0F}\x{2E10}\x{2E11}\x{2E12}" & _

;\x{2E13}\x{2E14}\x{2E15}\x{2E16}\x{2E17}\x{2E18}\x{2E19}\x{2E1A}\x{2E1B}\x{2E1C}\x{2E1D}\x{2E1E}\x{2E1F}\x{2E20}\x{2E21}
"\x{2E13}\x{2E14}\x{2E15}\x{2E16}\x{2E17}\x{2E18}\x{2E19}\x{2E1A}\x{2E1B}\x{2E1C}\x{2E1D}\x{2E1E}\x{2E1F}\x{2E20}\x{2E21}" & _

;\x{2E22}\x{2E23}\x{2E24}\x{2E25}\x{2E26}\x{2E27}\x{2E28}\x{2E29}\x{2E2A}\x{2E2B}\x{2E2C}\x{2E2D}\x{2E2E}\x{2E30}
"\x{2E22}\x{2E23}\x{2E24}\x{2E25}\x{2E26}\x{2E27}\x{2E28}\x{2E29}\x{2E2A}\x{2E2B}\x{2E2C}\x{2E2D}\x{2E2E}\x{2E30}\x{2E31}" & _

;                                                                               \x{3001}\x{3002}\x{3003}\x{3008}\x{3009}
"\x{2E32}\x{2E33}\x{2E34}\x{2E35}\x{2E36}\x{2E37}\x{2E38}\x{2E39}\x{2E3A}\x{2E3B}\x{3001}\x{3002}\x{3003}\x{3008}\x{3009}" & _

;\x{300A}\x{300B}\x{300C}\x{300D}\x{300E}\x{300F}\x{3010}\x{3011}\x{3014}\x{3015}\x{3016}\x{3017}\x{3018}\x{3019}\x{301A}
"\x{300A}\x{300B}\x{300C}\x{300D}\x{300E}\x{300F}\x{3010}\x{3011}\x{3014}\x{3015}\x{3016}\x{3017}\x{3018}\x{3019}\x{301A}" & _

;\x{301B}\x{301C}\x{301D}\x{301E}\x{301F}\x{3030}\x{303D}\x{30A0}\x{30FB}               \x{A60D}\x{A60E}\x{A60F}\x{A673}
"\x{301B}\x{301C}\x{301D}\x{301E}\x{301F}\x{3030}\x{303D}\x{30A0}\x{30FB}\x{A4FE}\x{A4FF}\x{A60D}\x{A60E}\x{A60F}\x{A673}" & _

;\x{A67E}                                               \x{A874}\x{A875}\x{A876}\x{A877}\x{A8CE}\x{A8CF}
"\x{A67E}\x{A6F2}\x{A6F3}\x{A6F4}\x{A6F5}\x{A6F6}\x{A6F7}\x{A874}\x{A875}\x{A876}\x{A877}\x{A8CE}\x{A8CF}\x{A8F8}\x{A8F9}" & _

;       \x{A92E}\x{A92F}\x{A95F}
"\x{A8FA}\x{A92E}\x{A92F}\x{A95F}\x{A9C1}\x{A9C2}\x{A9C3}\x{A9C4}\x{A9C5}\x{A9C6}\x{A9C7}\x{A9C8}\x{A9C9}\x{A9CA}\x{A9CB}" & _

;                               \x{AA5C}\x{AA5D}\x{AA5E}\x{AA5F}                                        \x{FD3E}\x{FD3F}
"\x{A9CC}\x{A9CD}\x{A9DE}\x{A9DF}\x{AA5C}\x{AA5D}\x{AA5E}\x{AA5F}\x{AADE}\x{AADF}\x{AAF0}\x{AAF1}\x{ABEB}\x{FD3E}\x{FD3F}" & _

;\x{FE10}\x{FE11}\x{FE12}\x{FE13}\x{FE14}\x{FE15}\x{FE16}\x{FE17}\x{FE18}\x{FE19}\x{FE30}\x{FE31}\x{FE32}\x{FE33}\x{FE34}
"\x{FE10}\x{FE11}\x{FE12}\x{FE13}\x{FE14}\x{FE15}\x{FE16}\x{FE17}\x{FE18}\x{FE19}\x{FE30}\x{FE31}\x{FE32}\x{FE33}\x{FE34}" & _

;\x{FE35}\x{FE36}\x{FE37}\x{FE38}\x{FE39}\x{FE3A}\x{FE3B}\x{FE3C}\x{FE3D}\x{FE3E}\x{FE3F}\x{FE40}\x{FE41}\x{FE42}\x{FE43}
"\x{FE35}\x{FE36}\x{FE37}\x{FE38}\x{FE39}\x{FE3A}\x{FE3B}\x{FE3C}\x{FE3D}\x{FE3E}\x{FE3F}\x{FE40}\x{FE41}\x{FE42}\x{FE43}" & _

;\x{FE44}\x{FE45}\x{FE46}\x{FE47}\x{FE48}\x{FE49}\x{FE4A}\x{FE4B}\x{FE4C}\x{FE4D}\x{FE4E}\x{FE4F}\x{FE50}\x{FE51}\x{FE52}
"\x{FE44}\x{FE45}\x{FE46}\x{FE47}\x{FE48}\x{FE49}\x{FE4A}\x{FE4B}\x{FE4C}\x{FE4D}\x{FE4E}\x{FE4F}\x{FE50}\x{FE51}\x{FE52}" & _

;\x{FE54}\x{FE55}\x{FE56}\x{FE57}\x{FE58}\x{FE59}\x{FE5A}\x{FE5B}\x{FE5C}\x{FE5D}\x{FE5E}\x{FE5F}\x{FE60}\x{FE61}\x{FE63}
"\x{FE54}\x{FE55}\x{FE56}\x{FE57}\x{FE58}\x{FE59}\x{FE5A}\x{FE5B}\x{FE5C}\x{FE5D}\x{FE5E}\x{FE5F}\x{FE60}\x{FE61}\x{FE63}" & _

;\x{FE68}\x{FE6A}\x{FE6B}\x{FF01}\x{FF02}\x{FF03}\x{FF05}\x{FF06}\x{FF07}\x{FF08}\x{FF09}\x{FF0A}\x{FF0C}\x{FF0D}\x{FF0E}
"\x{FE68}\x{FE6A}\x{FE6B}\x{FF01}\x{FF02}\x{FF03}\x{FF05}\x{FF06}\x{FF07}\x{FF08}\x{FF09}\x{FF0A}\x{FF0C}\x{FF0D}\x{FF0E}" & _

;\x{FF0F}\x{FF1A}\x{FF1B}\x{FF1F}\x{FF20}\x{FF3B}\x{FF3C}\x{FF3D}\x{FF3F}\x{FF5B}\x{FF5D}\x{FF5F}\x{FF60}\x{FF61}\x{FF62}
"\x{FF0F}\x{FF1A}\x{FF1B}\x{FF1F}\x{FF20}\x{FF3B}\x{FF3C}\x{FF3D}\x{FF3F}\x{FF5B}\x{FF5D}\x{FF5F}\x{FF60}\x{FF61}\x{FF62}]" & _

;\x{FF63}\x{FF64}\x{FF65}
"\x{FF63}\x{FF64}\x{FF65}", $sReplaceWith)
    Return $sText
EndFunc ;==> _StripPunctuation

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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...