while ((j>0) and (i>0)) do
begin
str_data := Copy(str_data ,1,i-1)+ Copy(str_data ,i+1,j);
i := Pos(' ',str_data );
j := length(str_data );
end;
檢查字串 dummyword 中是否含小數的數字, 把非數字移走
// replace non numeric and extra dot to space
firstdot := false;
for i := 1 to j do
begin
if not (dummyword in ['0'..'9','.']) then dummyword :=' '
else
if (dummyword = '.') then
if (not firstdot) then firstdot := true else dummyword := ' '
end;
// get rid of all space
i := Pos(' ',dummyword);
j := length(dummyword);
while ((j>0) and (i>0)) do
begin
dummyword := Copy(dummyword,1,i-1)+ Copy(dummyword,i+1,j);
i := Pos(' ',dummyword);
j := length(dummyword);
end;
抽出字串右面起指定數目字符
var str_data, str_extract:String;
str_length: integer;
str_extract := RightStr(str_data, str_length);
抽出字串左面起指定數目字符
var str_data, str_extract:String;
str_length: integer;
str_extract := LeftStr(str_data, str_length);
把文字變為整數
var str_data: String;
i: integer;
i := StrtoInt(str_data);
把HEX 文字變為整數
function TForm1.hexaToInt(s : string) : integer;
begin
if (s <> '') and (s[1] <> '$') then
result := strToInt('$' + s )
else
result := strToInt(s);
end;
把文字變為數字
var str_data: String;
i: real;
i := StrtoFloat(str_data);
把整數變為文字
var str_data: String;
i: integer;
str_data := InttoStr(i);
把數字變為文字
var str_data: String;
i: real;
str_data := FloattoStr(i);
但不支持Unicode,可改用其它方法,例如
for i:=1 to Length(Str) do
if copy(Str,i,1) = '先' then replaceString := replaceString + '後'
以下的function 會稍後補充例子
AdjustLineBreaks: Returns the string with all line breaks converted to true CR/LF sequences.
CompareStr: Compares two strings.
CompareText: Compares two strings without case sensitivity.
DupeString: Returns a string repeated a specified number of times.
ExtractStrings: Fills a string list with substrings parsed from a delimited list.
IsDelimiter: Returns True if a specified character in a string matches one of a set of delimiters starting from some position.
LastDelimiter: Returns the index of the last occurence in a string of the characters cpecified.
QuotedStr: Returns the quoted version of a string.
ReverseString: Returns a string in which the character order of a specified string is reversed.
SetLenght: Changes the size of a dynamic array or a string.
SetString: Sets the lenghth and contents of a given string.
Str: Formats a string from an integer or floating point variable.
StringOfChar: Returns a string containing a repeating character string of the length specified.
TrimLeft: Returns a string containing a copy of a specified string without leading spaces and control characters.
TrimRight: Returns a string containing a copy of a specified string without trailing spaces and control characters.
Val: Converts a string to a numeric value.
WrapText: Returns a string broken into multiple lines.