Wednesday, 18 January 2023

Instr & Substr functions in RTF

The substr function allows you to extract a substring from a string. The syntax for the substr function is:

substr(string, start_position, length)

string is the source string.

start_position is the position for extraction. The first position in the string is always 1.

length is the number of characters to extract

<?xdofx:substr('128.000',5,1)?>

 output = 0



The instr function returns the location of a substring in a string. The syntax for the instr function is:

instr(string1,string2,[start_position],[nth_appearance])

string1 is the string to search.

string2 is the substring to search for in string1.

start_position is the position in string1 where the search will start. The first position in the string is 1. If the start_position is negative, the function counts back start_position number of characters from the end of string1 and then searches towards the beginning of string1.

nth appearance is the nth appearance of string2.

<?xdofx:Instr('128.000','.',1)?>

output = 4



Here is an example to use substr and instr function together 

Suppose SSR_TOT_EN_TKNGPA = '128.000'

<?xdofx:substr(SSR_TOT_EN_TKNGPA,Instr(SSR_TOT_EN_TKNGPA,'.',1) + 1,1)?>

output = 0


No comments:

Post a Comment