This is probably something I’m overlooking on my part but I’m trying to create a Trim feature using the COPYSTR and STRLEN function. With the code below: FullDescription := COPYSTR(Item.Description,1,STRLEN(Item.Description)) + Item.“Excess Description”; I still get spaces in the output variable. Any ideas?
You could use the PADSTR() Function: From the Help File: Use this function to change the length of a string to a length you define. The system does this by either truncating the string or adding filler characters at the end of the string. NewString := PADSTR(String, Length [, FillCharacter]) Hope this helps:) Darren Bezzant, NCPS, NCSD Central Software Ludlow, New Brunswick, Canada firstname.lastname@example.org
trim or Pad? Trim just use FORMAT MyString:=Format(MyString) remove trailing spaces MyString:=Format(MyString,20) cuts up to 20 chars Ifyou have a lot of trailing spaces you could use the DelStr to remove double spaces MyString:=DelStr(MyString,’ ') cuts out all double spaces I assume that the problem is from Imported data of fixed length. David Cox MindSource (UK) Limited Navision Solutions Partner Email: email@example.com Web: www.mindsource.co.uk Edited by - David Cox on 2001 Mar 15 00:57:22
I’m still having no luck with trimming a text field in this dataport. I’ve tried using FORMAT and PADSTR but I still keep getting the spaces at the end of the first field. tempname := ‘’; tempname := FORMAT(Item.Description) + ’ '; IF Item.“Excess Description” <> ‘’ THEN tempname := tempname + FORMAT(Item.“Excess Description”); Note: I had it display the STRLEN of the Description field and it was 30 for every record. Any ideas?
I assume the object is to remove trailing spaces then concat the 2 strings // Remove Leading or Trailing Spaces! MyTxt := DELCHR(MyTxt, ‘<>’, ’ ‘); MyTxt:= MyTxt+’ '+MyTxt2; This will remove traiing blanks David Cox MindSource (UK) Limited Navision Solutions Partner Email: firstname.lastname@example.org Edited by - David Cox on 2001 Mar 16 00:10:47
Thanks, that worked. It’s a round about way of trimming text fields but it’s now going in my Misc. Functions code unit. It would all be much simpler if the STRLEN function worked. I’ve experimented with it and it gives erratic results. Generally it gives the maximum string length but occasionally not.
Michael The Leading or trailing spaces are part of the string as they are not null. So the STRLEN(Mystring) will include any spaces, this can be seen on your imported data when you select a field and the backgrond turns blue. MyTxt := DELCHR(MyTxt, ‘<>’, ’ '); // Deletes Spaces at the front or back of any string. Maybe NS could create us a function STRTRIM(MyString); David Cox MindSource (UK) Limited Navision Solutions Partner Email: email@example.com Web: www.mindsource.co.uk Edited by - David Cox on 2001 Mar 16 20:49:55
Looking for some string functions in the forums yesterday, and found this thread. Yes, it would be nice to have an extra string trim function in the IDE. Anyway, I know it might look crued, but I made my own and it seems to work…[:o)] 1. Create Function: TrimStr(String : Text) : Text 2: Code in the function: //Strip any leading and ending spaces String := DELCHR(String, ‘<>’, ’ '); //Add a space for next checking of spaces String := String + ’ '; //Now into checking each character FOR i := 1 TO STRLEN(String) DO IF (COPYSTR(String,i,1) = ’ ') AND (COPYSTR(String,i+1,1) = ’ ') THEN TempStr := TempStr ELSE TempStr := TempStr + COPYSTR(String,i,1); //Strip the last character as checking now done EXIT(COPYSTR(TempStr,1,50)); I’m sure there is a better logical solution. Puzzle me!! Jason Bradley UK
Will this become one of those best-function competition threads? [:D][:D] My take on the subject, straight from the archives [;)]:
TrimStr(String : Text) NewString : Text WHILE STRPOS(String,' ') > 0 DO String := DELSTR(String,STRPOS(String,' '),1); NewString := DELCHR(String,'<>');
Thanks for sharing this and I beleive this should become one of the best functions.