How can I get number from a string?

(the number should be atleast 7 digits long)

Is the string describing a number? e.g. "1234567"? If so, App Inventor will recognise the string as a number in your equation.

If this is not what you mean, then please give some examples.

{v[ ED 6732v+04 aUN%8S.y;ewYGMkqGj6
9kHUKvVP@Tqw0e60Xbadi) nU(uqPqr
cK1 DD6AiwbzDXHyf 61778352715 a*tN{%
X{5-Y?.#X.1jc0wFVZ{dn$Y_rY
[}g%k ;Y-e(Q8[Z @$91A+CQ/_wUCr.y
#V+c&p%:u[Pgn ,D&A{wNKmd{bt57t

How can I get the number more than 7 digits in a string?

Where does that string come from?

Write a procedure that reads the string character-by-character. If a number (char) is detected - add it to a variable, read the next character and so on - if 7 or more characters in a row a numbers, you have found the number, stored it in a variable and the procedure can stop. If the variable doesn't reach 7, clear it, continue to read char-by-char.

may be js can help you with this small extension , credit to @Juan_Antonio beause of this extension

use this code

var str = "v[ ED 6732v+04 aUN%8S.y;ewYGMkqGj6 9kHUKvVP@Tqw0e60Xbadi) nU(uqPqr cK1 DD6AiwbzDXHyf 61778352715 a*tN{% X{5-Y?.#X.1jc0wFVZ{dn$Y_rY [}g%k ;Y-e(Q8[Z @$91A+CQ/_wUCr.y #V+c&p%:u[Pgn ,D&A{wNKmd{bt57t";
var numbers = str.match(/\b\d{7,}\b/g);
numbers ? numbers.join(", ") : "No match";

or you can achieve it withoput extension with this blocks..split text one space ( we found there is a space so used )

if you are sure there will be a only one item will be there then you can use the below blocks, else if there is a possibility of multiple numbers mean you canuse the above block

1 Like

image


No extensions needed, draggable blocks.

1 Like

..and another :upside_down_face:

FindNumber.aia (3.6 KB)

1 Like

Loops? We don't need no stinkin' loops!

2 Likes

Wouldn't that collect all digits, not just a continuous row of digits?

The trick is the distinction between SPACE and empty text.

This is clearer:

1 Like

But it can be achieved just by using,

  1. For each item in the list
  2. Split text at space
  3. If logic
  4. Result.

Wont it be enough as said in post no. 6, third recommendation? No use of local variable until of there are multiple greater than 7 digits

use Regex extension:
image

2 Likes

Split text at spaces, use logic if length of text is greater than or equals to 7 and is number.

I think your 3rd solution is the best.

The local List isn't used and it is best not to run during Screen Initialisation - just call it in a Procedure (which can have an argument for an incoming string).

1 Like