So i have some long “Text” variables that i store in a DataTable.
im getting some specific Row from the DataTable and inject the Text in a “Text Render Component”
I know i could use Shift+Enter to do a return to line while i write the Text in the DataTable but that’s not really practical due to the presentation of DataTables.
My goal is to :
Get the selected Text
Count an amount of characters from the start (ie : 12 or 15)
I found a way to do this in blueprints! Let me explain my method to you:
First of all, create the following variables in your BP:
Input String (String) - This is the Text from your Data Table transformed into a String
Current Index (Int) - This is the initial position from where we wil start to count characters
Char Limit (Int) - This is the max characters per row
Cut Position (Int) - This is de position in the String where we will be cutting each row
Formatted String (String) - This is the resulting String with the new format
You need to get the text from your data table using the node “Get Data Table Row” (right click on “Out Row” and split it to get your text variable) and cast it to String, then store it in your “Input String” variable
Now get the length of your “Input String” variable and make a While Loop when “Current Index” is less than that length. You can set the text of your text render in the “Completed” pin by casting the “Formatted String” variable back to “Text” type here. (I’m goin to explain how to process that variable in the next steps)
Now, we need to cut our “Input String” in pieces. We will use the “Mid” node to do that. This node will count X characters (our “Char Limit” variable) from a start point (our “Current Index” variable) and return all the characters counted as a String. Then we will find the las space in that string using the Find Substring node. (note that you need to type an actual space in the “Substring” text box)
The next step is to check if we found a space character in the current string fragment and set our variables accordingly. If we find a space, we need to set our “Cut Position” variable adding the returned value from the Find Substring node to our “Current Index” variable. If we didn’t find a space we need to add our “Current Index” to our “Char Limit” instead “Cut Position”
The reason we want to find the last space of a row is to add the jump to a new line there instead of cutting a word in half.
Ok, now we have our string fragment and we know if we found a space, we need to put our currect fragment and the jump to a new line in our “Formatted String” variable. To do it we will use the following nodes immediately after we set our “Cut Position” variable (keep in mind that you need to insser a new line in the B text box of your Append node by using “shift+enter”). And the last thing to do is to set the “Current Index” variable by adding “Cut Position” + 1