Methods to count spaces in a string

HCC

Member
Hi,
how can I count the spaces in a string
and store the result in a macrodroid integer variable?

Input string:

myString = "alfa bravo charly delta echo foxtrott"

With the macrodroid magic string
{strlen=myString}
it is possible to get the string length.

Here is an example (macrodroid local variable "spaceINT"):

myString = "alfa bravo charly delta echo foxtrott"
spaceINT = {strlen=myString}

I'm experimenting with the macrodroid WHILE / DO loop and the "Text Manipulation"---> "substring".
The code will be ~12 lines long (I use an action block). -Since the code won't be ready for a few days,
I'm looking for a way to do it with regex.

How to do it e.g. with regex?
 

Pseudocyclic

Well-known member
Copy the string to a second string variable; use Text Manipulation to remove all the spaces; length of original string minus length of manipulated string = number of spaces.
 

Dm114

Well-known member
Hi,
how can I count the spaces in a string
and store the result in a macrodroid integer variable?

Input string:

myString = "alfa bravo charly delta echo foxtrott"

With the macrodroid magic string
{strlen=myString}
it is possible to get the string length.

Here is an example (macrodroid local variable "spaceINT"):

myString = "alfa bravo charly delta echo foxtrott"
spaceINT = {strlen=myString}

I'm experimenting with the macrodroid WHILE / DO loop and the "Text Manipulation"---> "substring".
The code will be ~12 lines long (I use an action block). -Since the code won't be ready for a few days,
I'm looking for a way to do it with regex.

How to do it e.g. with regex?
Use Text manipulation to extract spaces only in a working variable and then Strlen (2 lines only).
 

HCC

Member
Use Text manipulation to extract spaces only in a working variable and then Strlen (2 lines only).
-Sounds interesting. I don't know how to extract just the spaces found into a second string variable using the macrodroid "Text Manipulation" function.

The macrodroid "Text Manipulation" function has 8 options:

1 Substring
2 Replace all
3 Extract text (with the 3 sub-options: "First match" and "Group 1" and "Full match")
4 Upper case
5 Lower case
6 Trim whitespace
7 Split to array
8 Remove text (with the 2 sub-options: "plain text" and "Use Regex")
 
Last edited:

Dm114

Well-known member
-Sounds interesting. I don't know how to extract just the spaces found into a second string variable using the macrodroid "Text Manipulation" function.

The macrodroid "Text Manipulation" has 8 options:

1 Substring
2 Replace all
3 Extract text (with the 3 sub-options: "First match" and "Group 1" and "Full match")
4 Upper case
5 Lower case
6 Trim whitespace
7 Split to array
8 Remove text (with the 2 sub-options: "plain text" and "Use Regex")
Extract > Full match (with 1 space in search field) and that's it! 😉20240312_080954.jpg20240312_081904.jpg
 
Last edited:
Top