Jump to content

how to find unicode with stringregexp


Recommended Posts

I cannot seem to get this code to work

StringRegExp($iNumber, "[a-zA-Z0-9:+/\0611\0612\0673\0674\0669\0667\0666\0686\0687\0576\0603\0604\0605]{" & StringLen($aBase[1]) & "}", 3)

It is searching for this

$base13 = chrw(611)&","&chrw(612)&","&chrw(673)&","&chrw(674)&","&chrw(669)&","&chrw(667)&","&chrw(666)&","&chrw(686)&","&chrw(687)&","&chrw(576)&","&chrw(603)&","&chrw(604)&","&chrw(605)

I am trying to turn my base 13 unicode back to dec. But I can't get stringregexp to detect the unicode.

credit to malky and joke758 for base conversion codes.

Local $iReturn
Local $aBase = StringSplit($sChar, ",")
Local $iBase = $aBase[0]
Local $aTemp = StringRegExp($iNumber, "[a-zA-Z0-9:+/\0611\0612\0673\0674\0669\0667\0666\0686\0687\0576\0603\0604\0605]{" & StringLen($aBase[1]) & "}", 3)
For $i = 0 To UBound($aTemp) - 1
$iReturn += ($iBase ^ $i) * (_ArraySearch($aBase, $aTemp[UBound($aTemp) - 1 - $i], 0, 0, 1) - 1)
Next
Link to comment
Share on other sites

I'm currently running some tests on my PC so I can't try your code. Although I'm not sure if this will help or not, you might want to take a look at the following function _WinAPI_WideCharToMultiByte(). Like I said I'm not sure, but there's a lot of documentation on MSDN. If the UDF you are refering to converts to base13, I imagine it should also be able to convert it back to decimal. Perhaps you can simplify the task by trying a different approach.

Link to comment
Share on other sites

yes, but stringregex is the best way to do this, let me show you my full code and you will understand what i mean. i just cant get it to match unicode. i will look at that function soon.

#include <Array.au3>
#include <string.au3>
$base13 = chrw(611)&","&chrw(612)&","&chrw(673)&","&chrw(674)&","&chrw(669)&","&chrw(667)&","&chrw(666)&","&chrw(686)&","&chrw(687)&","&chrw(576)&","&chrw(603)&","&chrw(604)&","&chrw(605)

$number = Asc(InputBox ( "Decimal Converter", "Enter a character" ))
$Code = _Base($number, $base13)

$text = "Base13 : " & $Code & " -> Dec: " & _Dec($Code, $base13)

MsgBox(0, 'Base13', $text)

Func _Base($iDecNumber, $sChar)
Local $aBase = StringSplit($sChar, ",")
Local $iBase = $aBase[0]

Local $iLen = Int(Log($iDecNumber) / Log($iBase)) + 1

Dim $iUnit[$iLen + 1]
Local $iReturn
Local $iTemp = $iDecNumber

If $aBase[0] <> $iBase Then
SetError(1)
Return -1
EndIf

If $iDecNumber = 0 Then Return $aBase[1]

For $i = 1 To $iLen
For $i2 = 1 To $i - 1
$iTemp = $iTemp / $iBase
Next
$iUnit[$i] = $aBase[Mod($iTemp, $iBase) + 1]
$iTemp = $iDecNumber
Next

For $i = 1 To $iLen
$iReturn = $iUnit[$i] & $iReturn
Next

Return $iReturn
EndFunc ;==>_Base

Func _Dec($iNumber, $sChar)
Local $iReturn
Local $aBase = StringSplit($sChar, ",")
Local $iBase = $aBase[0]
Local $aTemp = StringRegExp($iNumber, "[a-zA-Z0-9:+/0611061206730674066906670666068606870576060306040605]{" & StringLen($aBase[1]) & "}", 3)
For $i = 0 To UBound($aTemp) - 1
$iReturn += ($iBase ^ $i) * (_ArraySearch($aBase, $aTemp[UBound($aTemp) - 1 - $i], 0, 0, 1) - 1)
Next

Return $iReturn
EndFunc ;==>_Dec
Edited by nullschritt
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...