Topic: SubString (Mid) Function
Does MVD support a subString, mid, extract type of function to get a piece of an existing string?
Also Left() or Right() functions?
Keith
My Visual Database → General → SubString (Mid) Function
Does MVD support a subString, mid, extract type of function to get a piece of an existing string?
Also Left() or Right() functions?
Keith
Hi Keith,
A few ways to do it.
I tend to use 'copy' (either copying the result to another field (as in the attached example) or back to itself); you can do 'left', 'mid' and 'right' all at the same time. Also in the attachment is a screenshot within the script editor where you can click on the 'functions' button to get a list of what's available.
Derek.
Derek,
Thanx for the reply and info... while I was looking at the Function List I just never equated "copy" at being the function I wanted !!
While you might not like this style of programming, my example, can you or anyone explain the oddity here.
//days := 'Sunday Monday Tuesday WednesdayThursday Friday Saturday ';
days := '' + format('%9s',['Sunday']) + format('%9s',['Monday']);
days := days + format('%9s',['Tuesday']) + format('%9s',['Wednesday']);
days := days + format('%9s',['Thursday']) +format('%9s',['Friday']);
days := days + format('%9s',['Saturday']);
ShowMessage('Days String =>' + days +'<=' + IntToStr(Length(days)));
showMessage('Day 5 is Thurs...' +copy(days,((5 * 9)-9)+1,9) +' OR '+
copy(days,((5 * 9)-9)+1,3));
if you un-comment the first sting (days) this works fine,
however using the format() option the first copy in the final ShowMessage works but the second
one is off by one char. Even adding a Trim() to the loading of Wednesday does not fix the issue.
Is there something I am missing with either the Copy() or the format() functions?
Regards,
Keith
Hi Keith,
Your 'copy' statement is fine.
Try changing your 'format' statement as follows:
days := '' + format('%-9s',['Sunday']) + format('%-9s',['Monday']);
days := days + format('%-9s',['Tuesday']) + format('%-9s',['Wednesday']);
days := days + format('%-9s',['Thursday']) +format('%-9s',['Friday']);
days := days + format('%-9s',['Saturday']);
So basically it's '%-9s' throughout.
I think that should fix it.
Derek.
Yes Sir, that does indeed fix things !!
Regards,
Keith
functions created from the substrings project written by Derek, above
//=================================================================
function left_mid_str(word:string;pos_ini:integer;len_sub:integer): string;
begin
result := copy(word,pos_ini,len_sub);
end;
//=================================================================
function rigth_str(word:string;len_sub:integer): string;
begin
result := copy(word,(length(word)-len_sub+1),len_sub);
end;
//=================================================================
procedure Form1_OnShow (Sender: TObject; Action: string);
begin
showmessage(left_mid_str('1234567890',1,3));
showmessage(rigth_str('1234567890',3));
end;
My Visual Database → General → SubString (Mid) Function
Powered by PunBB, supported by Informer Technologies, Inc.
Theme Hydrogen by Kushi