Svidos29
5th September 2018, 10:52
hi all,
i should try to delete some characters from a string with certains conditions. If i have that string longer than 20 i have to delete the first characters, until i arrive to 20.
How can i manage it ?
Thanks
tmannais
5th September 2018, 10:57
Try
output = str.substring$(your.string, len(your.string) - 20, len(your.string))
not tested though. Feel free to adjust where it needs to be done.
Svidos29
5th September 2018, 12:08
Hi,
thanks, but i've found also this way:
lng = len(trim$(field))
lng2 = 20
if lng > 20 then
diff = lng - lng2
field = field(diff;20)
endif
cheers,
NPRao
11th September 2018, 21:05
Since you are on the 10.2 release you can use the Standard Tools function -
str.remove$()
Syntax:
function string str.remove$ (const string string$, long offset, long nchars)
Description
Returns a copy of a string having a number of characters deleted, beginning at a specified character position.
Arguments
const string string$ a string
long offset the character position to begin deleting characters; note that:
if offset < 1, then nothing is removed
if offset > len(string$), then nothing is removed
long nchars the number of characters to remove; note that:
if nchars < 0, then all characters starting at offset are removed
if nchars = 0, then nothing is removed
if offset + nchars > len(string$), then all characters starting at offset are removed
Return values
A string equivalent to the specified string less the specified number of characters
Context
This function is implemented in the 4GL Tools and can be used in all script types. This function is available from TIV level 1700.