201
Views
2
Comments
Substring parts of  string
Question

Hi,

I have a question regarding substringing some dynamic parts of a string. 

My string looks something like this: 

{"Question1":"Answer1","Question2":"Answer2","Question3","Answer3"}

I want to be able to get the answer to the second question as an output so I can use that in following logic. I am able to get the answer when using a substring like: 

Substr(GetAnswers.List.Current.Data,
Index(GetAnswers.List.Current.Data,"Question2") + 12,7)

This works fine because I know the length of the answer but that will not always be the case of course. Since it will also have effect on answers later in the AnswerSet, I also don't know the starting position of the answer. 

Is there a way to search for the first comma or quote after the first index and get the index of that element from the parent string (so not the substring?

Basically what it needs to do is determine at what index the comma is, give that back and substract the initial index from the second index to determine the length of the substring. 


Regards,

Max

 

2018-10-18 08-34-00
Eric Bulters
 
MVP

Hi Max,

Maybe have a look at the JSONDeserialize action. This might help

2024-06-13 07-53-34
Paulo Moreira
 
MVP

Hi Max,

Please find attached an approach example to your question, following Eric's suggestion.

As an alternative, you can do a String Split (please refer to the Text System Component) on the string splitting by the comma (","), then iterate the resulting text list and perform a second String Split by ":", to get both the Questions and the Answers.

Hope this helps. 

Best regards,

Paulo Moreira

SubstringPartsOfString.oml
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.