schibsted / jslt

JSON query and transformation language
Apache License 2.0
638 stars 120 forks source link

index-of works on array but not string #345

Open samer1977 opened 6 months ago

samer1977 commented 6 months ago

We developers always think of string as an array of chars and function that applies to arrays should apply to strings including index-of, size...etc.

larsga commented 6 months ago

Slicing works for both arrays and strings. Size likewise. contains() searches for something in strings and arrays. It sounds like what you're asking for?

samer1977 commented 6 months ago

what Im looking for is similar to charindex function in sql, you pass string input and search char\chars and it will give the index of the first occurance

larsga commented 6 months ago

Hmmm. Looks like you're right that that's missing. If so, it's pretty incredible that we didn't add that before. Yeah, we may have to add that, perhaps by extending index-of() to work on strings.