Hi folks
I would love to do a bit of string operations and I fear the only way for me to accomplish what I want is through HomeyScript… However, I haven’t been able to figure out how to get it to work.
What I am looking for:
I have a variable with the value “Peter: Visit the library” now I want to remove "Peter: " from the variable so I can add “Visit the library” to the variable named “Peters todo list for today”.
I have been trying to use HomeyScript but since this is my first try, I just can’t get it to work.
It is important to note that I am not a developer, so any coding on my part has to be/will be really simple for me to also know, what I am doing.
I hope someone can help explain what I am doing wrong - or even better give an example of how to accomplish what I want so I can learn to use HomeyScript.
Here is the code I have been trying to use (which fails):
As arguments I input “Peter: ;”@Title
const inputString = args[0];
function removeStringA(inputString) {
// Split the input string by the semicolon
const parts = inputString.split(';');
// Ensure there are two parts (string A and string B)
if (parts.length !== 2) {
throw new Error('Input string must contain exactly one semicolon.');
}
// Extract string A and string B
const stringA = parts[0].trim();
let stringB = parts[1].trim();
// Check if string A is found in string B
if (stringB.includes(stringA)) {
// Remove string A from string B
stringB = stringB.replace(stringA, '').trim();
}
return stringB;
}