求助各位高手帮忙!!!

wj_gzmk 2007-05-14 03:41:46
我们的短信服务器要求发送短信的内容超过了移动公司规定的70字限制,请问怎么能在给定的字符串中截取。(我截取字符串的时候经常会出现乱码的现象,字符串中包括字符和汉字!!!)
...全文
105 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jadeluo 2007-05-14
  • 打赏
  • 举报
回复
如果是限定了每次发送的字节数的话, 可以写个函数来获取指定字节数的子串:

function String_Copy(sString: String; iStart:Integer; var iLen:Integer): String;
var
iLoop : Integer;
bHead : Boolean;
bTail : Boolean;
begin
if iStart + iLen - 1 >= Length(sString) then
iLen := Length(sString) - iStart + 1
else begin
bHead := False;
bTail := False;
for iLoop := iStart to iStart + iLen -1 do
begin
if bHead and not bTail then
bTail := True
else
if sString[iLoop] >= #160 then
begin
bHead := True;
bTail := False;
end;
end;
if bHead and not bTail then Dec(iLen);
end;
Result := Copy(sString, iStart, iLen);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
s, t : String;
i, j : Integer;
begin
s := '12345字符串ABCDE';

i := 1;
j := 6;
t := String_Copy(s, i, j); //返回'12345'
ShowMessage(t);
i := i + j;
j := 3;
t := String_Copy(s, i, j); //返回'字'
ShowMessage(t);
i := i + j;
j := 5;
t := String_Copy(s, i, j); //返回'符串A'
ShowMessage(t);
end;
chenzhuo 2007-05-14
  • 打赏
  • 举报
回复
把他定义为WideString类型吧!

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧