Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 02-29-2008, 04:06 PM
kbboykin kbboykin is offline
Senior Member
 
Join Date: May 2005
Posts: 371
Default How to extract last 4 letters of a string?

Hello All,

I have tried to figure this out from the samples but they all seem to work on everything but want I need. I admit I am not good with string extraction. What want to do is extract the "days" portion of strings like:

24 days, 1 days

I will then use this to locate info from a database limited to the string "days"

for example an edit box shows "28 days"

my pseudocode:

if edit box text ends in 'days' then

real code:

begin
vaxdata.vaxReq.Locate('agecode','DYS', []);
reResults.Lines.Add(vaxdata.vaxReqRequiredVax.Valu e);
end;

How to do this please.

Thanks in advance.

--Keith
Reply With Quote
  #2  
Old 02-29-2008, 05:19 PM
SourceCode SourceCode is offline
Senior Member
 
Join Date: Apr 2005
Posts: 810
Default RE: How to extract last 4 letters of a string?

var
sub : string;
myword : string;
begin
myword := edit1.text;
sub := Copy(myword,length(myword)-4,4);
if sub = 'days' then
showmessage('edit1.text contains the word days!);
end;






[link=http://homepages.ihug.co.nz/~fxnz/]FXNZ - Digital Solutions[/link]
Reply With Quote
  #3  
Old 02-29-2008, 08:32 PM
douglas douglas is offline
Senior Member
 
Join Date: Jul 2001
Posts: 7,695
Default RE: How to extract last 4 letters of a string?

Hi,
Hope it may help you..

if (Pos('days',lowercase(Edit1.text)) > 0) then
ShowMessage('days string present in Edit Text');

With Regards

Chapappu
Reply With Quote
  #4  
Old 02-29-2008, 08:50 PM
douglas douglas is offline
Senior Member
 
Join Date: Jul 2001
Posts: 7,695
Default RE: How to extract last 4 letters of a string?

To extract last 4 letters of a string..

var
S : String;
begin
s := Edit1.text;
s := Reversestring(copy(ReverseString(s),0,4));
showmessage(s);
end;

With Regards

Chapappu
Reply With Quote
  #5  
Old 03-01-2008, 01:25 AM
kbboykin kbboykin is offline
Senior Member
 
Join Date: May 2005
Posts: 371
Default RE: How to extract last 4 letters of a string?

This seems to be the only way it works. Thanks

--Keith
Reply With Quote
  #6  
Old 03-01-2008, 08:57 PM
SourceCode SourceCode is offline
Senior Member
 
Join Date: Apr 2005
Posts: 810
Default RE: How to extract last 4 letters of a string?

Can you explain how that was the ONLY WAY it works - only so others who visit this website can learn also..Thanks!





[link=http://homepages.ihug.co.nz/~fxnz/]FXNZ - Digital Solutions[/link]
Reply With Quote
  #7  
Old 03-02-2008, 02:56 AM
kbboykin kbboykin is offline
Senior Member
 
Join Date: May 2005
Posts: 371
Default RE: How to extract last 4 letters of a string?

I had tried very similar code as yours on my own. However, feeling that I must have done something wrong, I created a new BDS project with a form, editbox, and simple button. I put your code in the OnClick event and nothing happened when I clicked the button. I put the code from the other's suggestion and actually both worked. I am not sure what is wrong with your code, but I thought it should have worked too.

--Keith
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 10:22 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.