//1,函数代码
{
判断字符串是否包含汉字
// judgeStr:要判断的字符串
//posInt:第一个汉字位置
}
function TForm2.IsHaveChinese(judgeStr: string; var posInt: integer): boolean;
var
p: PWideChar; // 要判断的字符
count: integer; // 包含汉字位置
isHave: boolean; // 是否包含汉字返回值
begin
isHave := false; // 是否包含汉字返回值默认为false
count := 1; // 包含汉字位置默认为1
p := PWideChar(judgeStr); // 把要判断字符串转换
// 循环判断每个字符
while p^ <> #0 do
begin
case p^ of
#$4E00 .. #$9FA5:
begin
isHave := true; // 设置是否包含汉字返回值为true
posInt := count; // 设置包含汉字位置
break; // 退出循环
end;
end;
Inc(p);
Inc(count); // 包含汉字位置递增
end;
result := isHave;
end;
//2,例子:
procedure TForm2.Button3Click(Sender: TObject);
var
testStr1, testStr2: string;
posInt: integer;
begin
testStr1 := '12345';
testStr2 := '123汉字45';
if self.IsHaveChinese(testStr1, posInt) = true then
begin
ShowMessage(testStr1 + ' 包含汉字 :' + inttostr(posInt));
end
else
begin
ShowMessage(testStr1 + ' 不包含汉字');
end;
if self.IsHaveChinese(testStr2, posInt) = true then
begin
ShowMessage(testStr2 + ' 包含汉字 :' + inttostr(posInt));
end
else
begin
ShowMessage(testStr2 + ' 不包含汉字');
end;
end;
Delphi判断字符串中是否包含汉字,并返回汉字位置
推荐阅读
- android逆向奇技淫巧八:apk加壳(二代)和通用脱壳分析
- android逆向奇技淫巧九:frida常见java层的加密/hash算法自吐
- linux源码解读(一):进程的创建、调度和销毁
- android逆向奇技淫巧二十一:ida反反调试&加密算法跟踪(未完待续)(六)
- android逆向奇技淫巧十七:android客户端自动x红包(一):代码原理分析
- android逆向奇技淫巧十四:定制art内核(二):VMP逆向----仿method profiling跟踪jni函数执行
- android逆向奇技淫巧二十:findcrypt和findhash查找疑似加密函数(五)
- android逆向奇技淫巧二十五:x音另类抓包(十)
- android逆向奇技淫巧二十七:AOSP改源码制作沙箱实现“无痕”hook和避开server端风控
- pycharm 关联py之后sqlmap的使用