Character Converter
Version:
1.0
Date Updated:
06/20/2019 A small tool for converting characters.
Attachment | Size |
---|---|
character_converter.ms | 422.02 KB |
A small tool for converting characters.
Attachment | Size |
---|---|
character_converter.ms | 422.02 KB |
Comments
global _cmxs_script_start =
global _cmxs_script_start = undefined
global _cmxs_script_end = undefined
_cmxs_script_start = 1
try DestroyDialog code2StringRoll catch()
rollout code2StringRoll "Character Converter"
(
edittext edt_source "Original Code:" pos:[10,34] width:379 height:423
button btn1 "to String" pos:[397,100] width:152 height:30
checkbox chk_ass "Variable assignment" pos:[402,135] width:120 height:16
checkbox chk_trim "Trim the space before and after" pos:[402,160] width:120 height:16
edittext edt_ass "Variable name:" text:"source" pos:[402,180] width:140 height:20
button btn16 "Convert to hex. characters" pos:[397,205] width:152 height:30
button btns264 "string to base64" pos:[397,240] width:152 height:30
button btn642s "base64 to string" pos:[397,280] width:152 height:30
--button btnmd5 "转为MD5" pos:[397,320] width:152 height:30
edittext edt_Result "Result:" pos:[517,36] width:379 height:423
button btn_empty "Clear All" pos:[70,475] width:73 height:21
button btn_copy "Copy to Clipboard" pos:[565,473] width:120 height:21
on btn_empty pressed do edt_source.text = edt_Result.text = ""
on btn_copy pressed do setclipboardText edt_Result.text
--str 转 md5
fn md5Num str =
(
--字符串转为字节数组
encoding = dotnetclass "system.text.encoding"
StrbyteArr = encoding.UTF8.getbytes (str as string)
--加密字节数组
md5 = (dotnetclass "System.Security.Cryptography.HashAlgorithm").Create()
Md5byteArr = md5.ComputeHash(StrbyteArr)
--数组直接打成数字字符串
str = ""
for i in Md5byteArr do str += i as string
return str
)
--str 转 64
fn base64Str str =
(
encoding = dotnetclass "system.text.encoding"
base64class = dotnetclass "system.convert"
byteArr = encoding.UTF8.getbytes str
base64 = base64class.tobase64string byteArr
)
--64码转字符串
fn strBase64 b64 =
(
encoding = dotnetclass "system.text.encoding"
base64class = dotnetclass "system.convert"
encoding.UTF8.getstring (base64class.frombase64string b64)
)
--整体字符串转移转换
fn code2Str str =
(
NewStr = ""
for i=1 to str.count do
(
local strF
if str[i] == "\"" then (strF = "\\\"")
else if str[i] == "\\" then (strF = "\\\\")
else StrF = str[i]
NewStr += StrF
)
return ( NewStr)
)
--带赋值的转换
fn code2StrAss _str _ass trim:true =
(
f = _str as stringStream
endStr = _ass + " = \"\"" + "\n"
while not eof f do
(
str = readLine f
NewStr = ""
for i=1 to str.count do
(
local strF
if str[i] == "\"" then (strF = "\\\"")
else if str[i] == "\\" then (strF = "\\\\")
else StrF = str[i]
NewStr += StrF
)
NetStr = dotnet.ValueToDotNetObject NewStr (dotNetClass "System.String")
ns = ""
if trim then
(
ns = NetStr.Trim() + "\\n"
)
else
(
ns = NetStr.Tostring() + "\\n"
)
endStr += ( "append " + _ass + " (\"" + ns + "\")" + "\n" )
)
endStr
)
fn str2Unicode16 str =
(
if str.count > 0 then
(
endStr = ""
for c=1 to str.count do
(
char = str[c]
if char != " " then
(
encoding = dotnetclass "system.text.encoding"
byteArr = encoding.Unicode.getbytes char --将字符作为Unicode分拆为byte
netchar = dotnetclass "system.charing"
new16 = ""
for i = byteArr.count to 1 by -1 do
(
char16 = formattedPrint byteArr[i] format:"x" --和下面一样的max方法
--char16 = netchar.format "{0:x}" i --把每个个byte转为16 charing
new16 += char16
)
endStr += ( @"\x" + new16 )
) else endStr += " "
)
endStr
)
)
on btn1 pressed do
(
if chk_ass.state then
(
edt_Result.text = code2StrAss (edt_source.text) (edt_ass.text) trim:chk_trim.state
)
else
(
edt_Result.text = "\"" + code2Str (edt_source.text) + "\""
)
)
on btn16 pressed do
(
if edt_source.text != "" do edt_Result.text = "\"" + str2Unicode16 (edt_source.text) + "\""
)
on btn16 Rightclick do
(
str = "messagebox " + edt_Result.text
try execute str catch(messagebox "我哪里知道出了什么错误!!!")
)
on btns264 pressed do
(
if edt_source.text != "" do edt_Result.text = base64Str (edt_source.text)
)
on btn642s pressed do
(
if edt_source.text != "" do try edt_Result.text = (strBase64 (edt_source.text)) catch(messagebox "Incorrect Base64 code")
)
/* on btnmd5 pressed do
(
if edt_source.text != "" do try edt_Result.text = (md5Num (edt_source.text)) catch(messagebox "错误了")
) */
)
createdialog code2StringRoll 950 550
_cmxs_script_end = 1
.
But why appending multiple lines one by one instead of single multi-line string assignment?
Something like this:
source = "one two three"
good job
good job