Hi, Does someone know how we can delete a all word from a text variable. For instance VArTExt := ‘Navision is surely the best’ becomes Navision is the best. With Delchr, how? I don’t want it to delete all included letters in the others words (Navision i th bt) Thank You,
What about DELSTR ?
from C/SIDE Reference DELSTR (String) Use this function to delete a substring inside a string (text or code). NewString := DELSTR(String, Position [, Length]) NewString Data type: text constant or code The resulting string. String Data type: text constant or code The input string. Position Data type: integer The position of the first character you want to delete. Position must be greater than zero (0). If Position exceeds the length of String, DELSTR returns the original string, without deleting anything. Length Data type: integer This tells the system how many characters to delete. Length must be greater than zero (0). If you omit Length, the system deletes all characters starting with Position and continuing to the end of the string.
So yours could be like this:
String := 'Navision is surely the best' ; DeleteString := 'surely'; NewString := DELSTR(String, STRPOS(String, DeleteString), STRLEN(DeleteString)); Regards, Jörg
Hi John, Off the top of my head, and this might not be the best way, but you could use STRPOS to search for the substring and return the position of the starting character of it, and then use DELSTR to delete the substr, using the STRPOS result and length of the substring as the parameters. So, in your example, IntVar := STRPOS(VArTExt,'surely '); VArTExt := DELSTR(VArTExt,IntVar,7); I can’t remember if DELSTR returns an error if the position paramter is 0, but if so an IF IntVar > 0 condition would sort it. Hope that helps. Edit: Don’t you just hate it when someone sneaks a reply in whilst you’re typing? [;)]
NewString := DELSTR(String, STRPOS(String, DeleteString), STRLEN(DeleteString));
If you know that the substr is going to be mid-sentence, then shouldn’t you probably use STRLEN(DeleteString)+1 as the length parameter to avoid leaving a double space between the remaining words?
Thanks a lot I forgot STRPOS [:)]