Hello all,
My current scenario is as follows;
I have a gallery with 4 text inputs. Each of these inputs have a 35 character limit. This is sent to an API call, where it may respond with a suggestion for the full value of text outputs.
If the suggested value is > 35, I need to gracefully split the string across these text inputs, by word, not by the raw position in the string. (I don't want to cut words in half just because they are character 35 and 36)
I have the following formula, which returns me a table with each space separated word, the position in the original string that the space was at, and the position in the original string that the space and the word end at.
Formula:
// Define the string
Set(varString, "Sunrise paints the sky with hues of gold and red");
Set(varStringLength, Len(varString));
ClearCollect(SplitString,
AddColumns(
Split(varString, " "),
"SpacePosition",
If(
ThisRecord.Value = First(Split(varString, " ")).Value,
0,
If(
IsBlank(LookUp(Split(varString, " "), Value = ThisRecord.Value, Value)),
Find(ThisRecord.Value, varString) - 1,
Find(ThisRecord.Value, varString, Find(LookUp(Split(varString, " "), Value = ThisRecord.Value, Value), varString) + 1) - 1
)
),
"EndPosition",
If(
ThisRecord.Value = First(Split(varString, " ")).Value,
0,
If(
IsBlank(LookUp(Split(varString, " "), Value = ThisRecord.Value, Value)),
Find(ThisRecord.Value, varString) - 1,
Find(ThisRecord.Value, varString, Find(LookUp(Split(varString, " "), Value = ThisRecord.Value, Value), varString) + 1) - 1
))
+ Len(ThisRecord.Value)
)
);
For example:
Sunrise paints the sky with hues of gold and red is the suggested text.
Rather than the result looking like;
Row 1: Sunrise paints the sky with hues o
Row 2: f gold and red is the suggested
The result should be:
Row 1: Sunrise paints the sky with hues
Row 2: of gold and red is
How can I form the strings for each row? I am not opposed to abandoning my original code.