删除特定字符后的文本 [英] Delete text after specific character

查看:48
本文介绍了删除特定字符后的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在TEdit框中有文字:'955-986,总计= 32'

I have the text inside TEdit box: '955-986, total = 32'

我如何删除逗号后的所有文本,因此只会保留'955-986'

How would I delete all text after the comma, so it will only left '955-986'

我试图限制TEdit的长度,但是它并没有达到我想要的效果.

I tried to limit the TEdit Length, but it's not working as I wanted it to be.

推荐答案

如果没有逗号怎么办?完整的非剪切字符串还是空字符串?

What if there'd be no comma? full non-cut string or empty string ?

以下是您限制字符串长度的想法,但仅在发现至少一个逗号时才适用.

Below is your idea of limiting string length, but only applied if at least one comma was found.

var 
    tmpStr:string;
    commaPosition:integer; 
begin
  tmpStr := Edit1.Text;
  commaPosition := pos(',',tmpStr);
  if commaPosition > 0 then begin
     SetLength(tmpStr, commaPosition - 1);
     Edit1.Text := tmpStr;
  end;
end;

这篇关于删除特定字符后的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆