ACCII 轉 String |
答題得分者是:hagar
|
juneo
高階會員 發表:103 回覆:190 積分:118 註冊:2004-05-13 發送簡訊給我 |
請問 將 123 轉為ACSII 得到 49-50-51 ,'-'是分隔符號
如何能將49-50-51 轉回字串,因為我只有英文及數字格式(不含中文)
所以用ord 轉成ACSII ,想知道用什麼方法可以轉回String 程式在此請各位大大幫忙
http://delphi.ktop.com.tw/topic.php?TOPIC_ID=67454 程式片段如下
procedure TForm1.Button1Click(Sender: TObject); begin // String To ACSII Edit2.Text:=StringToAcsii(Edit1.Text); // ACSII To String Edit3.Text:= AcsiiToString(Edit2.Text); end; // String To ACSII function TForm1.StringToAcsii(S:string):String ; Var I:Integer; G:String; begin For I:=1 to Length(S) do Begin G:=G IntToStr(ord(S[I])); If I數學 程式 經驗=不懂^^ |
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
|
Fishman
尊榮會員 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
Hi All, 野人獻曝一下
< class="code">
function TForm1.AcsiiToString(S:String):String ;
var
I,C : Integer;
SS : String;
ST : TStrings;
begin
SS := '';
ST := TStringList.Create;
ST.Delimiter := '-';
ST.DelimitedText := S;
try
for I := 0 to ST.Count - 1 do
begin
if TryStrToInt(ST[i],C) then
try
SS := SS Chr(c);
except;
end
end;
finally
ST.Free;
Result := SS;
end;
end;
----------------------------------
小弟才疏學淺,若有謬誤尚請不吝指教
----------------------------------
------
Fishman |
juneo
高階會員 發表:103 回覆:190 積分:118 註冊:2004-05-13 發送簡訊給我 |
感謝兩位大大快速的回覆^^
還有一些疑問希望兩位大大能幫解疑惑,謝謝
純粹討論,因為我想把程式都弄懂
疑惑一:
s := Chr(StrToInt(IntToStr('$' '49')));
出現型態不符問題,因為'49'已經是字串,當我去掉IntToStr也是不能轉換回來
不知道問題出現在哪?
疑惑二:
Fishman大大程式可以完全轉換回原本字串但是變數C好像沒有傳進數值
卻可以Chr(c),可以幫我解釋紅色那兩行嗎?謝謝
function TForm1.AcsiiToString(S:String):String ; var I,C : Integer; //宣告變數C了 SS : String; ST : TStrings; begin SS := ''; ST := TStringList.Create; ST.Delimiter := '-'; ST.DelimitedText := S; try for I := 0 to ST.Count - 1 do begin if TryStrToInt(ST[i],C) then try SS := SS Chr(c); except; end end; finally ST.Free; Result := SS; end; end;數學 程式 經驗=不懂^^ |
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
|
Fishman
尊榮會員 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
Hi juneo, TryStrToInt function Converts a string that represents an integer (decimal or hex notation) to a number with Boolean success code. Unit SysUtils Category type conversion routines Delphi syntax: function TryStrToInt(const S: string; out Value: Integer): Boolean; C syntax: extern PACKAGE bool __fastcall TryStrToInt(const AnsiString S, int &Value); Description TryStrToInt converts the string S, which represents an integer-type number in either decimal or hexadecimal notation, into a number, which is assigned to Value. If S does not represent a valid number, TryStrToInt returns false; otherwise TryStrToInt returns true. Chr function Returns the character for a specified ASCII value. Unit System Category character manipulation routines Delphi syntax: function Chr(X: Byte): Char; Description Chr returns the character with the ordinal value (ASCII value) of the byte-type expression, X. ----------------------------------
小弟才疏學淺,若有謬誤尚請不吝指教
----------------------------------
------
Fishman |
juneo
高階會員 發表:103 回覆:190 積分:118 註冊:2004-05-13 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |