Ooops
January 26, 2021, 06:08:33 AM

### Author Topic: [bb] Number from String by Cpt. Sovok [ 1+ years ago ]  (Read 454 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bb] Number from String by Cpt. Sovok [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : Number from String
Author : Cpt. Sovok
Posted : 1+ years ago

Description : If you want a Number from a String in which the Numbers are seperated by a comma ("12,456,23,23456"), use this function...

Code :
Code: BlitzBasic
1. ; Extract Numbers from an String.
2. ; Robert Gerlach 2001
3. ; www.robsite.de
4.
5. numberstring\$ = "1,22,333"
6. Print numberstring\$
7. Print stringtonumber(numberstring\$, 1)
8. Print stringtonumber(numberstring\$, 2)
9. Print stringtonumber(numberstring\$, 3)
10.
11.
12. Function stringtonumber(numberstring\$, position)
13. n_number = 1 ; Number Of Numbers.
14. lastcomma = 1
15. For i = 1 To Len(numberstring\$)
16. If Mid(numberstring\$, i, 1) = "," Or i = Len(numberstring\$) Then
17. If n_number = position Then number\$ = Mid(numberstring\$, lastcomma, i)
18. lastcomma = i+1
19. n_number = n_number + 1
20. EndIf
21. Next
22. Return number\$
23. End Function
24.