EDIT: Thank you for so many responses and apologies for ambiguous question, and poorly constructed example. I didn't mean to split the word by the uppercase character. I literally mean to split the string after a specific character like 'X', 'r', or 'o'.
I'm trying to split a long string of repeating words like "FooXXBarBazXBar ..." into a list of words ['Fo', 'o', 'X', 'X', 'Bar', 'Baz', 'X', 'Bar' ...].
In c I would create a new array of characters and copy characters one by one, inserting a delimiter after a specific character, to later split on the delimiter like this:
{
char *newString = malloc(sizeof(char)*200);
int offset=0;
//copy characters from old string to the new one, inserting ';' after a specific character
for (int i = 0, n = strlen(string); i < n; i++)
{
newString[i+offset] = string[i];
if ((string[i] == 'o') || (string[i] == 'r') || (string[i] == 'z') || (string[i] == 'X'))
{
offset += 1;
newString[i+offset] = ';';
}
}
//split the string into an array of strings on the delimiter ';'
split_string(newString);
}
I'm still a beginner, so it's probably also not that great, but it works.
I'm trying to work around this in python, but cannot come up with a good approach.
How would you go about it? Thanks :)