当前位置:首页>开发>正文

Delphi字符操作求助 delphi符号问题

2023-05-06 15:12:42 互联网 未知 开发

 Delphi字符操作求助 delphi符号问题

Delphi字符操作求助

1. 没什么好说的。

2. 转换成十六进制串用IntToHex函数,取得字符的编码值用Ord函数。以下是示例:

11111111120
22222 functionToHexStr(constS: string): string
var
  HexStr: string
  Value, I: Integer
begin
  Result := 
  forI := 1toLength(S) do
  begin
    Value := Ord(S[i]) //取得ASCII值
    HexStr := IntToHex(Value, 2) //转换为16进制串
    HexStr := HexStr[2]   HexStr[1] // 取反置换
    ifI = 1then// 如果是首位则减    begin
      Value := StrToInt($  HexStr)
      Dec(Value)
      HexStr := IntToHex(Value, 2)
    end
    Result := Result   HexStr    
  end
end
 
procedureTForm1.Button1Click(Sender: TObject)
begin
  Edit1.Text := ToHexStr(Edit1.Text)
end

3.
把前面得到的字符串,先进行分解,然后把每个转换成数值,保存到字节数组中,最后用Seek定位文件位置,然后用BlockWrite来写入字节数组。


11111111120
222222 procedureWriteMyFile(constFileName, HexStr: string)
var
  Buf: PByte
  AList: TStringList
  AStream: TFileStream
  I: Integer
begin
  AList := TStringList.Create
  AList.DelimitedText := HexStr  //指定要分割的十六进制串
  AList.Delimiter :=   //指定以空格字符分割
  GetMem(Buf, AList.Count) //为Byte数组分配空间
  forI := 0toAList.Count - 1do//把分割后的结果存到Byte数组
    Buf[i] := StrToInt($  AList[i])
 
  AStream := TFileStream.Create(FileName, fmOpenWrite)  //以写方式打开文件
  AStream.Seek($160, soFromBeginning) //定位
  AStream.Write(Buf, AList.Count) //写入Byte数组
  AStream.Free
  AList.Free
end
 
procedureTForm1.Button1Click(Sender: TObject) 
begin
  Edit1.Text := ToHexStr(Edit1.Text)
  WriteMyFile(A.bin, Edit1.Text) 
end

4.
只要你已经得到了各个数组,那也是比较容易的事。

delphi符号问题

Delphi里面,用两个单引号表示一个单引号
比如 String a
a := aaa
注意前面三个单引号,第一个为括住字符串的标志,后面两个代表一个单引号
a代表的字符串实际上是 aaa
知道了这点以后,你应该可以用来组合出SELECT语句了。

delphi截取字符问题

将<td表内的数据取出就可以了
var
o: OleVariant
begin
For i:= 0 to webbrowser1.OleObject.Document.getElementsByTagName(td).Length - 1 Do
Begin o:=webbrowser1.OleObject.Document.getElementsByTagName(td).item(ii)
showmessage(o.innertext)
end
用正则也是个不错的选择

delphi 字符转义

用" ", 就是两个" ", 代表一个" ", 这是PASCAL的基本常识.
比如, 要声明一个字符串常量S, 其值为 "Whos the girl?", 做法是

const
S = Whos the girl?

delphi 字符取值问题,麻烦帮帮忙看看哦

如果分隔符固定就很好做了。
用TStrings类型的DelimitedText,设置好Delimiter:=,,就可以把这不超过12个数据分隔开来,然后在根据::分开成两部分就行了。

怎样在Delphi中处理字符串?

//取左边数n个字符function LeftStr (const S : string const N : Integer): stringbeginendbegin//取字符串中Ch字符左边的内容function LeftTillStr (const S : string const Ch : Char): string M: Integer M := Pos (Ch, S) if M < 2 then Result := else Result := Copy (S, 1, M - 1)end//取右边数n个字符 Result := Copy (S, 1, N)function RightStr (const S : string const N : Integer): stringvar M: Integerbegin M := Length (S) - N 1 if M < 1 then M := 1 Result := Copy (S, M, N)endvar//取字符串中Ch字符右边的内容function RightAfterChStr (const S : String const Ch : Char): Stringvar M: Integerbegin M := Pos (Ch, S) if M = 0 then Result := else Result := Copy (S, M 1, Length (S) - M)end

delphi 取出一个字符在字符串出现的次数

function stringn(s1,s2:string):integer
begin
result:=0
while pos(s1,s2)>=0 do
begin
s2:=copy(s2,pos(s1,s2) 1,9999) //假设s2最大长度为9999个字符
result:=result 1
end
end

最新文章