Storing a substring within a string (setstr())ΒΆ
setstr() |
Store a substring within a string |
SYNTAX
setstr(field_id, position, length, source)
This function takes length characters from the text string source, and places them into the text string field_id, starting at the position in field_id indicated by position. The relevant characters of field_id are over-written. If field_id is not long enough, the excess characters of source are discarded. The first character of field_id counts as position number 1.
The function returns the new value of field_id.
The valid types for the arguments are as follows:
field_id |
Must be an alphanumeric or binary field. If it is not, then no copying takes place and a null string is returned. |
position |
Numeric constant or expression. |
length |
Numeric constant or expression. |
source |
Alphanumeric or binary field, or a string constant. |
This function returns 0 if Ok and 1 otherwise (wrong field_id or position received)
NOTES
The first character of field_id is position 1. Setting position to zero has the same effect as setting it to 1. If it is less than zero, or greater than the field length, field_id is returned unchanged.
EXAMPLE
!temp Source,,a20
!temp Dest,,a10
+textbox DestBox at 35,10 {
field = tmp.Dest
title = "OUTPUT FROM SETSTR"
}
tmp.Source = "TEN_CHARACTERS"
tmp.Dest = "NO="
display DestBox [NO= ]
tmp.Dest = setstr(tmp.Dest,4,3,tmp.Source)
display DestBox [NO=TEN ]