在 Delphi 中使用 SubStr + 提取子字符串复制?
我在delphi中具有一个功能,
var
Ramoativ : String;
filteredRamoativ: String;
begin
Ramoativ := '15 - Serviços';
filteredRamoativ := copy(Ramoativ, 1, SubString(Ramoativ, 1, '-'));
end;
输出必须为= 15
字符串可以具有2位数以上的数字,因此RamoAtiv可以是'13823849 -Serviços',但是 - 始终将数字与文本分开。
我的想法是使用功能来定位“ - ”的位置,并将其用作复制的论点,但是我很难做到这一点
I have a function in Delphi
var
Ramoativ : String;
filteredRamoativ: String;
begin
Ramoativ := '15 - Serviços';
filteredRamoativ := copy(Ramoativ, 1, SubString(Ramoativ, 1, '-'));
end;
The output must be = 15
The String can have more than 2 digits number, so Ramoativ can be '13823849 - Serviços', but the - will always separate the number from text.
My idea is using a function to locate the position of "-" and use it as an argument for copy, but I am having difficulties doing it
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的想法是正确的方法。但是,Delphi没有
substring()
函数。要在另一个字符串中搜索子字节的位置,请使用system.pos.pos.pos.pos.pos.pos.pos.pos.pos.pos ()
函数,例如:另外,delphi具有
strutils.leftstr()
功能是从字符串的左侧提取子字符串,例如:Your idea is the correct way to go. However, Delphi does not have a
SubString()
function. To search for the position of a substring in another string, use theSystem.Pos()
function instead, eg:Also, Delphi has a
StrUtils.LeftStr()
function to extract a substring from the left-hand edge of a string, eg: