获取包含数字的第一个字 [英] Get First word that contains numbers
本文介绍了获取包含数字的第一个字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
procedure TForm1.Button4Click(Sender:TObject);
var
SourceString:String;
strArray:TArray< string> ;;;
i:整数;
begin
SourceString:='圣史蒂芬St 6.A II.f 9';
strArray:= SourceString.Split(['']);
for i:= 0 to Length(strArray)-1 do
showmessage(strArray [i]);
结束;
结果: p>
Saint
Steven
St
6.A
II.f
9
我想获得包含数字的第一个Word。在例子中:'6.A'。
任何人都有一个想法如何?
解决方案
测试字符串是否包含一个数字,循环显示字符串并检查每个字符。例如:
function ContainsDigit(const S:string):Boolean;
var
C:Char;
开始
在S do
中如果(C> ='0')和(C <='9')然后
exit(True);
exit(False);
结束
或者您可能更喜欢使用 System.Character
单位。
使用
System.Character;
....
函数ContainsDigit(const S:string):Boolean;
var
C:Char;
开始
在S do
如果C.IsDigit然后
exit(True);
exit(False);
结束
Anyone can help with how can I find the first full Word that contains numbers? I have an adress, for example:
procedure TForm1.Button4Click(Sender: TObject);
var
SourceString : String;
strArray : TArray<string>;
i : Integer;
begin
SourceString := 'Saint Steven St 6.A II.f 9';
strArray := SourceString.Split([' ']);
for i := 0 to Length(strArray)-1 do
showmessage(strArray[i]);
end;
Result:
Saint
Steven
St
6.A
II.f
9
I want to get the first Word that contain number. In the example: '6.A'.
Anyone have an idea how?
解决方案
Test if a string contains a digit by looping of the string and checking each character. For instance:
function ContainsDigit(const S: string): Boolean;
var
C: Char;
begin
for C in S do
if (C >= '0') and (C <= '9') then
exit(True);
exit(False);
end;
Or you might prefer to write the if statement using the record helper methods from the System.Character
unit.
uses
System.Character;
....
function ContainsDigit(const S: string): Boolean;
var
C: Char;
begin
for C in S do
if C.IsDigit then
exit(True);
exit(False);
end;
这篇关于获取包含数字的第一个字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文