右截取字符串函数怎么写?在线等待急!(100分)

  • 主题发起人 hyzzhxia
  • 开始时间
H

hyzzhxia

Unregistered / Unconfirmed
GUEST, unregistred user!
我想截取一个字符串得右边字符,谁能告诉我,谢谢。最好其他的截取字符串函数也告知。好像delphi的字符串处理功能不强对吗?
 
首先uses StrUtils,
然后RightStr
后面有一大堆函数
AnsiContainsStr function

Indicates whether one string is a (case-sensitive) substring of another.

AnsiContainsText function

Indicates whether one string is a (case-insensitive) substring of another.

AnsiEndsStr function

Indicates whether one string is a (case-sensitive) suffix of another.

AnsiEndsText function

Indicates whether one string is a (case-insensitive) suffix of another.

AnsiIndexStr function

Provides the index of a specified string in an array of strings.

AnsiIndexText function

Provides the index of a specified string in an array of strings.

AnsiMatchStr function

Indicates whether an array of strings contains an exact match to a specified string.

AnsiMatchText function

Indicates whether an array of strings contains a case-insensitive match to a specified string.

AnsiReplaceStr function

Replaces all occurrences of a substring with another string.

AnsiReplaceText function

Replaces all case-insensitive matches of a substring with another string.

AnsiResemblesProc variable

Controls the algorithm used by AnsiResemblesText to determine when two strings are similar.

AnsiResemblesText function

Indicates whether two strings are similar.

AnsiStartsStr function

Indicates whether one string is a (case-sensitive) prefix of another.

AnsiStartsText function

Indicates whether one string is a (case-insensitive) prefix of another.

DecodeSoundExInt function

Converts an integer representation of a SoundEx encoding into the corresponding phonetic string.

DecodeSoundExWord function

Converts a Word representation of a SoundEx encoding into the corresponding phonetic string.

DupeString function

Returns the concatenation of a string with itself a specified number of repeats.

IfThen function

Conditionally returns one of two specified values.

LeftStr function

Returns the substring of a specified length that appears at the start of a string.

MidStr function

Returns the substring of a specified length that appears at a specified position in a string.

RandomFrom function

Returns a randomly selected element from an array.

ReverseString function

Returns the reverse of a specified string.

RightStr function

Returns the substring of a specified length that appears at the end of a string.

SearchBuf function

Locates a substring within a text buffer.

SoundEx function

Converts a string into its SoundEx representation.

SoundExCompare function

Compares the SoundEx representations of two strings.

SoundExInt function

Converts a string into an integer that represents its phonetic value.

SoundExProc function

Indicates whether two strings are similar.

SoundExSimilar function

Indicates whether two strings are similar.

SoundExWord function

Converts a string into a Word that represents its phonetic value.

StuffString function

Inserts a substring into a specified position of a string, replacing the current characters.
 
Copy+Pos
可以解决绝大部分的问题!
如:
var
s1,s:string;
begin
s:='12345';
s1:=copy(s,3,3);
showmessage(s1);
//s1=345;

end;
 
copy,delete
 
RightStr
LeftStr
是现成的函数为什么不用呢??
要先uses StrUtils
 
function RightStr(Str: String; Start: Integer): String;
begin
Result := Copy(Str, Start, length(Str) - Start + 1);
end;
 
// 从右去掉某一特定字符st。默认为空格
function Rtrim(s: string; st: string = ' '): string;
var
i, j: integer;
begin
j := 0;
for i := length(s) downto 1 do
begin
if Copy(s, i, 1) = st then
j := j + 1
else
Break;
end;
Result := Copy(s, 1, length(s) - j );
end;
 

呵呵,都是现成的函数啊,函数多的是。
例如 StrRScan
 
用trimright()函数啊
左截取用trimleft
 
可以自己用copy, pos, length 写一个:
function RightStr(str:string, len:integer);
begin
RightStr(str, length(str)-len+1, len)
end;
 
多人接受答案了。
 
顶部