Story
I am making a map where two players are given halves of a message, and then have to travel through their own separate courses to meet at a central point, where the message must be put together and submitted as a whole within a certain time limit to win the game.
Problem
In order to make this function, the string with the message must be split in half before being sent to the players. I need to find a way to split a string at a certain index.
Core question
How can one split an NBT string at an arbitrary index using commands?
Given a string and an index...
{String:"Life is a bowl of cherries",Index:10b}can you split the string at that index into two strings?
{ResultStringA:"Life is a ",ResultStringB:"bowl of cherries"}Rules:
- The index can be related to the split point in any way. In this example, the index represents the character immediately following the split, but in your answer, I don't mind how it relates. It's up to you whether your index is 0-based or 1-based or whether it represents the character immediately before or after the split. It just needs to make sense.
- Important: The index must be variable, that is, you can't hard-code the index. Preferably, the index will be another changeable NBT number or scoreboard value that can be anything you wish before the machine starts.
Applications of solutions to this problem
The answers to this problem will also be useful if you are trying to do these tasks:
- Extract a substring from an NBT string: To extract a substring from a string, split it into three portions, and take the middle portion.