Good day! I have a problem, i am request a data to an api and the data on my api i want to add a text or integer on it on a specific position, is there a way that i can request and add a text or nnumbers on a specific position hope there is a way, for a mean time been trying the regex replace. but doesnt work on me. thanks! hope someone can see this
You can manipulate data returned from an API response before storing or displaying it. If you want to insert text or integers at a specific position in the string, you can use string manipulation functions rather than regex, as they are often simpler and more efficient in this context.
When working with lists, you can access and manipulate the current position or a specific position in the list. Here's how to handle inserting or modifying values at specific positions in a list effectively:
Accessing and Modifying List Elements
Accessing Current Item: When iterating over a list (for example, in a For Each loop), you can access the current item using:
List.Current.VALUE
Accessing a Specific Position: To access an element at a specific index in the list, you can use:
List[POSITION].VALUE
Here, POSITION is a zero-based index (e.g., 0 for the first item, 1 for the second item).
do you have example on regex? maybe im using it wrong. thanks!
Hi,
Jesu, so you tried RegEx but it doesn't work (yet). Maybe you share the work done and a bit more detailed description of what you try to achieve. That way someone can have a meaningful reply that maybe helps you. Right now there is little information you shared for someone to work with.
Regards,
Daniel
sorry sir cant really share it due to its our school project thanks for understanding!
sorry then I cannot help
If it's a school project there's nothing keeping you from sharing, as it is not a business secret or something.
Hi Jesu,
I don't understand what it is you want to achieve. You are talking about an API, but also about adding something at a certain position. Is it an API you consume or an API you expose? Is it the result of an API you want to handle, or do you need to output something that has been changed?
Also, you are talking about "insert text or integers at a specific position in the string", do you actually need to insert it, or overwrite the current content? Is it at a fixed position, or a position based on the current contents of the string? Why do you try to use regex? Have you looked into the built-in functions Index and Substr?
If you know Index/Position then you can achieve it using build-in Substr(), Length() functions like below
Substr(OriginalString,0,5)+"text/value"+Substr(OriginalString ,9,Length(OriginalString))
If you're consuming API then apply in on "On Before Request"/"On After Response" based on your requirement.
Hi @jesu versoPlease find the below answer I hope this will work for you.
Deserialize the API Response: If the response is in JSON, use JSONDeserialize to parse it into a structure or record list so you can access specific fields.
String Manipulation: If you need to add text or numbers to specific positions in a string, consider using a combination of Substring, Concatenate, and Length functions:
Regex Usage: OutSystems supports regex, but it can be tricky. Instead of replacing, you might use regex to locate the position, then apply Substring and Concatenate around that position.
Using Text Functions: OutSystems has built-in functions for text handling, such as TextToInteger, IntegerToText, etc. Use these to ensure that you can add numbers or convert between types where needed.
Please don't use ChatGPT to answer questions Ankit, it helps no-one!
Hello @jesu verso,
Without you providing an explanation for your problem, we won't be able to help you.
Can you give an example of what you need?
I have this API request, and in a specific field, I need to make my modification.
You are already dealing with Regex issues, and perhaps the solution doesn't even involve Regex...
Regex is the only solution to take the text or number at any particular position.