Forum Discussion
DRP
Nimbostratus
May 07, 2015Looking for iRule to convert non-ascii character to ascii
We have users having French character in their name and so F5 convert entire att.dn into hex string. And so comparison against the DN (to see what OU the user is in) breaks.
attr.dn' set to '0x...
adack
Nimbostratus
Jun 12, 2019That's what worked for me:
proc hex2ascii {sHex} {
# latin-1 supplement, unicode u+0000 - u+00ff
set iByte 0
# check if string begins with '0x'
if { [scan $sHex {0x%s} sHex] > 0} {
# loop each character
foreach sChar [ split [binary format H* $sHex] ""] {
# convert to decimal
scan $sChar %c iChar
if {$iChar < 0x80} {
# standard ascii
append sAscii $sChar
} elseif {$iChar > 0xc2} {
set iByte [expr ({$iChar} - 0xc2) * 0x40]
} elseif {$iChar < 0xc2} {
# convert to ascii
append sAscii "[format %c [expr {$iByte} + {$iChar}]]"
set iByte 0
}
}
return $sAscii
} else {
return $sHex
}
}Calling the function with the following attribute will return ASCII
[call hex2ascii 0x434e3d....]Hope this helps.
- CA_ValliOct 19, 2021
MVP
Used this today for the same purpose, it's working.
[encoding] TCL commands seem not to be available in iRule (tested in v13-14)
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
