This is the forum archive of Homey. For more information about Homey, visit the Official Homey website.
The Homey Community has been moved to https://community.athom.com.
This forum is now read-only for archive purposes.
The Homey Community has been moved to https://community.athom.com.
This forum is now read-only for archive purposes.
How to remove substring from string (/specific text from 'speech' input text)
k1s
Member
Hello, does anyone know how to remove text from another section of text?
Say I've got a text variable TextA which has a value "Remove This. I only want this".
How can I create a new variable TextB with value "I only want this" ?
I tried using the creating another variable TextC with value "Remove This. " and then another Logic card that sets TextB by subtracting TextC from TextA, but none worked, e.g.
{{TextA}} - {{TextC}}
{{{TextA}} - {{TextC}}}
{{$TextA}}} - {{$TextC}}
{{$TextA}}} - {{$TextC}}
(No idea what the sytax should be or even where to look it up or what language Homey uses, so I'm just guessing in the wind with the curly brackets and dollar signs ...)
Say I've got a text variable TextA which has a value "Remove This. I only want this".
How can I create a new variable TextB with value "I only want this" ?
I tried using the creating another variable TextC with value "Remove This. " and then another Logic card that sets TextB by subtracting TextC from TextA, but none worked, e.g.
{{TextA}} - {{TextC}}
{{{TextA}} - {{TextC}}}
{{$TextA}}} - {{$TextC}}
{{$TextA}}} - {{$TextC}}
(No idea what the sytax should be or even where to look it up or what language Homey uses, so I'm just guessing in the wind with the curly brackets and dollar signs ...)
Comments
https://forum.athom.com/discussion/840/better-logic-variable-management
maybe there is something for you?
Thanks, I can't tell if you're pointing me to a specific example or to the thread in general. I see there is an app called HomeyScripts and have looked at the github pages. It is clearly aimed at developers and beyond simple understanding from a non-programmer. I see some examples of using tags and tokens (I don't know what a token is), but not how to strip text from a the text stored as a tag.
I'm guessing from the extension ".js" that perhaps Homey uses a version of javascript - is that right? Googling how to remove text from a string in javascript I found this example:
var str = "data-123";
...which is supposed to change the variable str from "data-123" to just "123".
So presumably my version could be something like:
var TextC = "Remove This. ";
But...
When I tried to put this into a flow, like this:
It didn't work. The push message just showed $TextB
I tried again with BetterLogic instead of Logic, like this:
...to see if it would change the variable values, but in fact looking in Settings after the flow ran, I saw all of the 'Last Set' 'Values' were blank, so obviously the syntax is not correct.
Did you Visit https://homeyscript.athom.com to manage your scripts? That is where you have to enter the JavaScript lines.
The way you made your Flows is not going to work, this has to be done in the HomeyScript environment.
That's fair enough, but if you do actually know how to do it, it would be much kinder just to tell me. I'm not a programmer, nor do I have the time or inclination to become one. I'm just trying to recoup some of the significant investment in time I already made into this Homey as a simple home user. I know nothing about javascript, nor HomeyScript.
I installed the app and created the following script:
I hit Save & Test, and got this:
---------------- Script returned: undefined
I have no idea what that means or what to do with it
Edit-1:
did some further investigation an came to this: (args is the input text from your Flow)
// insert here the destination of your changed text
return(rest);
Edit-2: //The result can be put in a "Better Logic" (String) variable:
//console.log("In=", strg, " >>> result=", rest );
//parts from https://forum.athom.com/discussion/3666/homeyscript-share-your-scripts-main-discussion-topic/p2
In your last example, is 'args' the same as in the first example var TextA = "Remove This. I only want this"; ??
When you say "The result can be put in a "Better Logic" (String) variable", what do you mean exactly? Do you mean I put this:
//console.log("In=", strg, " >>> result=", rest );
"star"-ing this topic on the top of this page, will send you a message when the topic is updated.
===========================================================================
.
here starts the explaining of the solution to the problem you asked: "how to remove text from another section of text?"
Tested with the text: "Remove This. I only want this"
Translation of the Dutch texts in the above picture:
^^ A user said something ^^ Execute a script with an Argument ^^whatever you like, like send to TV
"MyText" is a Variable, type String, made in Better Logic.
Axualy these are the lines you realy need in your HomeyScript:
bl.apiPut('MyText/' + rest); // places the found rest in the Better Logic variable "MyText"
Your post comes out like this:
I can't really work out what you said.
Edit: read again, I added some extra info, can't make it more clear, sorry.