1. 字符串和数组应用
#include
;字符串的大小写转换
$str01 = “abdcefg”;
$result01 = StringUpper($str01);
$result02 = StringLower($result01);
MsgBox(64,”大小写转换结果”,”大写:” & $result01 & Chr(13) & “小写:” & $result02);
;字符串的长度
$str02 = “acer01acer02acer03acer04acer05”;
$len = StringLen($str02);
MsgBox(64,”长度”,”字符串的长度为:” & $len );
;返回指定数量的字符串
$str03 = StringLeft($str02,12);
$str04 = StringRight($str02,12);
MsgBox(64,”返回指定字符数”,”左边的12个字符:” & $str03 & Chr(13) & “右边的12个字符:” & $str04);
;字符串替换
$str05 = “a-b-c-d-e-f-g”;
$str06 = StringReplace($str05,”-“,”=”);
$replaceNum = @extended;
MsgBox(64,”字符替换”,”原串:” & $str05 & Chr(13) & “替换后的串:” & $str06 & Chr(13) & “替换个数:” & $replaceNum);
;字符串分割
$str07 = “123,456,789,0,a,d,gg”;
$array01 = StringSplit($str07,”,”,1);
MsgBox(64,”分割字符串”, “分割后的数量:” & $array01[0] & Chr(13) & “第3个串:” & $array01[3]);
MsgBox(64,”数组长度”, “长度:” & $array01[0]);
;将字符串转换为数组
$array02 = StringToASCIIArray($str01);;默认为UNICODE
$array03 = StringToASCIIArray($str01,”GBK”);
$array04 = StringToASCIIArray($str01,2,4,”GBK”);;从第2个开始第5个结束
_ArrayDisplay($array02,””);
_ArrayDisplay($array03,””);
MsgBox(64,”数组长度”, “长度:” & $array02[0]);
2. 字符串转数组
; Binary ANSI to String
$buffer = StringToBinary(“Hello – 你好”)
MsgBox(4096, “String() representation” , $buffer)
$buffer = BinaryToString($buffer)
MsgBox(4096, “BinaryToString() ANSI representation” , $buffer)
; Binary UTF16-LE to String
$buffer = StringToBinary(“Hello – 你好”, 2)
MsgBox(4096, “String() representation” , $buffer)
$buffer = BinaryToString($buffer, 2)
MsgBox(4096, “BinaryToString() UTF16-LE representation” , $buffer)
; Binary UTF16-BE to String
$buffer = StringToBinary(“Hello – 你好”, 3)
MsgBox(4096, “String() representation” , $buffer)
$buffer = BinaryToString($buffer, 3)
MsgBox(4096, “BinaryToString() UTF16-BE representation” , $buffer)
; Binary UTF8 to String
$buffer = StringToBinary(“Hello – 你好”, 4)
MsgBox(4096, “String() representation” , $buffer)
$buffer = BinaryToString($buffer, 4)
MsgBox(4096, “BinaryToString() UTF8 representation” , $buffer)
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/231406.html原文链接:https://javaforall.net
