Jump to content

Recommended Posts

Posted (edited)
Local $key_G = Chr(0xD0) ;uppercase Ğ
Local $key_I = Chr(0xDD) ;uppercase İ
Local $key_S = Chr(0xDE) ;uppercase Ş
Local $key_G = Chr(0xF0) ;lowercase ğ
Local $key_I = Chr(0xFD) ;lowercase ı
Local $key_S = Chr(0xFE) ;lowercase ş

Local $string = "ĞİŞğış"
$string = StringRegExpReplace($string, "Ğ", "G")
$string = StringRegExpReplace($string, "İ", "I")
$string = StringRegExpReplace($string, "Ş", "S")
$string = StringRegExpReplace($string, "ğ", "g")
$string = StringRegExpReplace($string, "ı", "i")
$string = StringRegExpReplace($string, "ş", "s")
Local $result = ConsoleWrite($string) ;GISgis

Hello guys,

I need to rewrite some Turkish letters and I use these codes to do so.

How can I do these 6 commands with a single command?

Edited by mixim
Posted (edited)

I am sure there is a way to do this with pure regex using StringRegExpReplace() however since the matches are simple enough my thought process is to use a function that contains all your corresponding matches and replacements in an array or map or something and just use StringReplace()

 

Also you can try nesting functions.

 

$sString = "+h!s is @ test"

$sNewString = StringReplace(StringReplace(StringReplace($sString, "+", "t"), "!", "i"), "@", "a")

MsgBox(0, "", $sNewString)

 

Edited by ViciousXUSMC
Posted
1 hour ago, ViciousXUSMC said:

I am sure there is a way to do this with pure regex using StringRegExpReplace() however since the matches are simple enough my thought process is to use a function that contains all your corresponding matches and replacements in an array or map or something and just use StringReplace()

 

Actually I am wondering if I could do it with pattern definition.

Posted
10 minutes ago, ViciousXUSMC said:

The main rule of RegEx is only use RegEx when its needed

The main rule of typing on an IPad while in the shower is “cut and paste” :)

Code hard, but don’t hard code...

Posted (edited)
Local $string = "ğĞçÇşŞüÜöÖıİ"
Local $a[12][12] = [[ "ğ", "Ğ", "ç", "Ç", "ş", "Ş", "ü", "Ü", "ö", "Ö", "ı", "İ" ], _
                    [ "g", "G", "c", "C", "s", "S", "u", "U", "o", "O", "i", "I" ]]
For $i = 0 To 11
    $string = StringReplace($string, $a[0][$i], $a[1][$i], 0, 1)
Next
Local $result = ConsoleWrite($string) ;gGcCsSuUoOiI

I made that for now, I guess I'll go with it this way.😖

Thank you so much for your helping.

Edited by mixim
Posted

Here's how to remove diacritics from accented letters in a Unicode string using a single regex replacement:

; Unicode Normalization Forms
Global Enum $UNF_NormC = 1, $UNF_NormD, $UNF_NormKC = 5, $UNF_NormKD

Func _Unaccent($s, $iMode = 0)
    Local Static $aPat = [ _
            "(*UCP)[\x{300}-\x{36F}`'¨^¸¯]", _    ; $iMode = 0 : remove combining accents only
            "(*UCP)\p{Mn}|\p{Lm}|\p{Sk}" _        ; $iMode = 1 :     "       "       "    and modifying letters
            ]
    Return StringRegExpReplace(_UNF_Change($s, $UNF_NormD), $aPat[Mod($iMode, 2)], "")
EndFunc   ;==>_Unaccent

; change UNF (Unicode Normalization Form)
Func _UNF_Change($sIn, $iForm)
    If $iForm = $UNF_NormC Or $iForm = $UNF_NormD Or $iForm = $UNF_NormKC Or $iForm = $UNF_NormKD Then
        Local $aRet = DllCall("Normaliz.dll", "int", "NormalizeString", "int", $iForm, "wstr", $sIn, "int", -1, "ptr", 0, "int", 0)
        Local $tOut = DllStructCreate("wchar[" & 2 * ($aRet[0] + 20) & "]")
        $aRet = DllCall("Normaliz.dll", "int", "NormalizeString", "int", $iForm, "wstr", $sIn, "int", -1, "ptr", DllStructGetPtr($tOut, 1), "int", 2 * ($aRet[0] + 20))
        Return DllStructGetData($tOut, 1)
    Else
        SetError(1, 0, $sIn)
    EndIf
EndFunc   ;==>_UNF_Change

However Turkish dotless "i" is not an accented letter and needs to be dealt with explicitely. So:

Local $s = "ğĞçÇşŞüÜöÖıİ  ЁЃЌЍӁ" ; also works for other scripts like cyrillic, etc.
Local $sUnTurkished = _Unaccent(StringReplace($s, "ı", "i"))

 

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)

Posted (edited)

@jchd This had so great, now I can use this for all lang.
Thank you very very much, respects.

Edited by mixim

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
  • Recently Browsing   0 members

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