Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
167 views
Welcome To Ask or Share your Answers For Others

1 Answer

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...