Is there a simple way to detect for any number in a string or a way to compare 2 strings and if they are different play a sound?
Example of a string that I'm using that has no numbers (I used getTextFromActiveWindow):
(how do I put all this text into a string?)
"STEERS
IN-STORE
We don’t have any steers for you to do right now. If you have a bad, or no internet connection, this can happen.
We don’t have any steers for you to do right now. If you have a bad, or no internet connection, this can happen.
vypr"
Here is one that has numbers that I want to detect and play a sound when they are found:
"STEERS
5
IN-STORE
10
POINTS
10
POINTS
10
POINTS
10
POINTS
10
POINTS
We don’t have any steers for you to do right now. If you have a bad, or no internet connection, this can happen.
vypr"
Thanks for any help.
Detect number in a string.
Moderator: Martin
Re: Detect number in a string.
This will give you all numbers
findAll('string', '\\d+')
To compare
Use expression
string1 != string2
findAll('string', '\\d+')
To compare
Use expression
string1 != string2
Re: Detect number in a string.
And how would I put
"STEERS
IN-STORE
We don’t have any steers for you to do right now. If you have a bad, or no internet connection, this can happen.
We don’t have any steers for you to do right now. If you have a bad, or no internet connection, this can happen.
vypr"
into a variable to compare it against?
This is what I'm trying:
Then in the expression condition, I'm using:
My thinking is that if comp does not contain a number then it will be true. If comp does contain a number it will be false and trigger my sound.
For some reason when there are no numbers it makes my expression false and triggers the sound.
Thanks
"STEERS
IN-STORE
We don’t have any steers for you to do right now. If you have a bad, or no internet connection, this can happen.
We don’t have any steers for you to do right now. If you have a bad, or no internet connection, this can happen.
vypr"
into a variable to compare it against?
This is what I'm trying:
Code: Select all
sleep (1000);
text = getTextInActiveWindow();
sleep (1000);
comp = 0;
comp = findAll('text', '\\d+') ;
Code: Select all
comp == null
For some reason when there are no numbers it makes my expression false and triggers the sound.

Thanks
Last edited by robchoc on 07 Dec 2018 15:53, edited 1 time in total.
Re: Detect number in a string.
Put it in global variable.
Or
Replace line breaks with \n
Or
Replace line breaks with \n
Code: Select all
string2 = "STEERS\nIN-STORE\nWe don’t have any steers for you to do right now. If you have a bad, or no internet connection, this can happen.\nWe don’t have any steers for you to do right now. If you have a bad, or no internet connection, this can happen.\nvypr"
Re: Detect number in a string.
Fastest way to convert the line break to the proper escaped char (\n), is copy and paste it sample text in Regex tester at script/expression. Scroll down and copy the matches() or any other function for the first parameter. This will convert the unseen char too, including the tab (\t), which is always the best way to spot the invisible mysterius character.
The other way, if you are sure every line break is only \n, and you need the text to be easier to read, add the \n, but separate them with +. You have to do it manually.
I make a flow, just to create something like this. So I passed the text to the flow, and the output is just like above, double quoted at each line with plus sign to concat.
The other way, if you are sure every line break is only \n, and you need the text to be easier to read, add the \n, but separate them with +. You have to do it manually.
Code: Select all
string =
"STEERS" +
"IN-STORE" +
"We don’t have any steers for you to do right now. If you have a bad, or no internet connection, this can happen." +
"We don’t have any steers for you to do right now. If you have a bad, or no internet connection, this can happen." +
"vypr" ;
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: Detect number in a string.
Thanks
Was starting to get concerned about your whereabouts. Glad you are back.
Was starting to get concerned about your whereabouts. Glad you are back.

Re: Detect number in a string.


Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.