Sure, no problem. I think that my reply takes longer to register because it probably triggered some additional checks because of code, or spam filter or something, not really sure why that happens, but when I saw my first reply appear, I made a change to it to tidy the code and add a if/else clause, and I guess that that again triggered the checks.... So I suspect that the updated post will appear either later today or tomorrow... But you got the idea from reply, that using string-length(substring-before())+1 will provide you with the positional index for the substring you are looking for. The if/else clause I added was just to use a contains() to see if the substring is present or not, else you'll always get a value of 1 based on the formula. So better to check if the string is present first, and then calculate the position etc.
Regards.
Original Message:
Sent: 11-03-2024 12:22
From: YVON LEDUC
Subject: Looking for a function that returns the position of a string within a string
Thanks ASHARP for your solution even thought somehow, it does not appears in the post.
I guess I am slowing down with old age but so used to have an actual function at my disposal. I was able to reach my goal using your idea.
Thanks.
His solution was mainly to use a combination of substring-before and string-length to get a similar result.
pos("ABCDEF", "DEF") = string-length(substring-before("ABCDEF", "DEF")+1)
------------------------------
YVON LEDUC
Original Message:
Sent: 11-01-2024 13:38
From: YVON LEDUC
Subject: Looking for a function that returns the position of a string within a string
Hello all.
I am looking for a function that would return the position of a string within a string to be used in a slax script. I've been searching in the documentation but can't find anything close to what I want.
There is the "contains" function which will tell me if one string exists within another string but can't find one that would return the position. I can write my own, but why reinvent the wheel if one exists.
Thanks.
------------------------------
YVON LEDUC
------------------------------