# Confusion between strings and numbers

**URL:** <https://forum.xojo.com/t/confusion-between-strings-and-numbers/88794>\
**Category:** General\
**Created:** [August 24, 2026, 1:41pm UTC](https://forum.xojo.com/t/confusion-between-strings-and-numbers/88794 "2026-08-24T13:41:04Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benoît\_Bouillon](https://forum.xojo.com/letter_avatar_proxy/v4/letter/b/919ad9/32.png) [@Benoît\_Bouillon](https://forum.xojo.com/u/Beno%C3%AEt_Bouillon)\
**Post date:** [August 24, 2026, 1:41pm UTC](https://forum.xojo.com/t/confusion-between-strings-and-numbers/88794/1 "2026-08-24T13:41:04Z")

</div>

Hello friends,  
I just ran into a strange situation.  
I have a string: “v. 15. → Naniser”.  
I want to extract the value 15 using a loop, since there might be multiple numbers.  
The program interprets “Naniser” as NaN.  
It works once I add `IsNumeric.`  
Can you explain why?

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [August 24, 2026, 2:05pm UTC](https://forum.xojo.com/t/confusion-between-strings-and-numbers/88794/2 "2026-08-24T14:05:47Z")

</div>

“Nansier” is not a number but the framework parser looks for “NaN”, case insensitive at the start of the string, is my best guess. NaN does mean “Not a Number” after all, so more-or-less correct in this instance 😀. Do you expect to encounter “NaN”? If so then I’d do a direct case sensitive comparison for that case rather than converting.

Whether or not you know the format of the input string, you’re likely better off with RegEx, especially if this is an operation you need to perform frequently. Then you can handle multiple numeric string results within the same container string using a loop quite easily.

---

<div class="post-metadata">

**Author:** ![Sascha\_S](https://forum.xojo.com/user_avatar/forum.xojo.com/sascha_s/32/22328_2.png) [@Sascha\_S](https://forum.xojo.com/u/Sascha_S)\
**Post date:** [August 25, 2026, 7:51am UTC](https://forum.xojo.com/t/confusion-between-strings-and-numbers/88794/4 "2026-08-25T07:51:18Z")

</div>

> [@Anthony\_G\_Cyphers](#):
>
> you’re likely better off with RegEx

_Untested code:_

```auto
Var extractedNumbers() As String
Var rx As New RegEx
rx.SearchPattern = "\d+"

Var match As RegExMatch = rx.Search(inputString) // e.g. “v. 15. → Naniser”

While match <> Nil
  extractedNumbers.Add match.SubExpressionString(0) // "15"
  match = rx.Search()
End While

```

---

<div class="post-metadata">

**Author:** ![Michael\_Hußmann](https://forum.xojo.com/user_avatar/forum.xojo.com/michael_hu%C3%9Fmann/32/438_2.png) [@Michael\_Hußmann](https://forum.xojo.com/u/Michael_Hu%C3%9Fmann)\
**Post date:** [August 25, 2026, 12:46pm UTC](https://forum.xojo.com/t/confusion-between-strings-and-numbers/88794/5 "2026-08-25T12:46:41Z")

</div>

Just an addition: While ‘NaN’ means ‘Not a Number’ it is a technically valid value of a variable of type Double and you can assign it to such a variable. Mathematically it is an invalid value, like what you would get by calculating the square root of a negative number.

(Maybe I should get slapped on my wrist for this but I have sometimes used a sqrt(-1) value to indicate that the actual value isn’t currently known.)

---

<div class="post-metadata">

**Author:** ![Benoît\_Bouillon](https://forum.xojo.com/letter_avatar_proxy/v4/letter/b/919ad9/32.png) [@Benoît\_Bouillon](https://forum.xojo.com/u/Beno%C3%AEt_Bouillon)\
**Post date:** [August 25, 2026, 5:13pm UTC](https://forum.xojo.com/t/confusion-between-strings-and-numbers/88794/6 "2026-08-25T17:13:02Z")

</div>

Many thanks for the explanations and the code as well!  
What I don’t understand is that my variable is declared as a string.  
And thanks also for teaching me about RegEx.

---

<div class="post-metadata">

**Author:** ![Julia\_Truchsess](https://forum.xojo.com/user_avatar/forum.xojo.com/julia_truchsess/32/499_2.png) [@Julia\_Truchsess](https://forum.xojo.com/u/Julia_Truchsess)\
**Post date:** [August 25, 2026, 5:16pm UTC](https://forum.xojo.com/t/confusion-between-strings-and-numbers/88794/7 "2026-08-25T17:16:56Z")

</div>

> [@Benoît\_Bouillon](#):
>
> What I don’t understand is that my variable is declared as a string.

Can you show us your code?

---

<div class="post-metadata">

**Author:** ![Benoît\_Bouillon](https://forum.xojo.com/letter_avatar_proxy/v4/letter/b/919ad9/32.png) [@Benoît\_Bouillon](https://forum.xojo.com/u/Beno%C3%AEt_Bouillon)\
**Post date:** [August 25, 2026, 5:47pm UTC](https://forum.xojo.com/t/confusion-between-strings-and-numbers/88794/8 "2026-08-25T17:47:55Z")

</div>

```auto
Dim NumS(-1) As String
if NumS(i) = "01." OR NumS(i) = "02." OR ( Val(NumS(i)) >= 10 AND Val(NumS(i)) <= 210 ) Then
  Num_Conjug.Append( Val(NumS(i)) ) // On mémorise les nombres.
end if

```

---

<div class="post-metadata">

**Author:** ![Michael\_Hußmann](https://forum.xojo.com/user_avatar/forum.xojo.com/michael_hu%C3%9Fmann/32/438_2.png) [@Michael\_Hußmann](https://forum.xojo.com/u/Michael_Hu%C3%9Fmann)\
**Post date:** [August 25, 2026, 10:20pm UTC](https://forum.xojo.com/t/confusion-between-strings-and-numbers/88794/9 "2026-08-25T22:20:41Z")

</div>

As it stands this code snippet doesn’t make much sense. Where is the value of the variable i coming from? Did you forget to include a For loop?

You start out with an empty string array but in the second line you assume it somehow got filled – NumS(i) would raise an error if NumS was still empty.

That NumS is declared as an array of strings _does_ make sense though.

---

<div class="post-metadata">

**Author:** ![Benoît\_Bouillon](https://forum.xojo.com/letter_avatar_proxy/v4/letter/b/919ad9/32.png) [@Benoît\_Bouillon](https://forum.xojo.com/u/Beno%C3%AEt_Bouillon)\
**Post date:** [August 25, 2026, 10:33pm UTC](https://forum.xojo.com/t/confusion-between-strings-and-numbers/88794/10 "2026-08-25T22:33:32Z")

</div>

In the age of AI, I hope my humble human intelligence at least had the sense to increment `i`.  
The reason I’m asking is that, out of 69,000 records, I ran into this problem and only with `naniser`.  
Of course, I didn’t include all the code.

---

<div class="post-metadata">

**Author:** ![Michael\_Hußmann](https://forum.xojo.com/user_avatar/forum.xojo.com/michael_hu%C3%9Fmann/32/438_2.png) [@Michael\_Hußmann](https://forum.xojo.com/u/Michael_Hu%C3%9Fmann)\
**Post date:** [August 25, 2026, 10:41pm UTC](https://forum.xojo.com/t/confusion-between-strings-and-numbers/88794/11 "2026-08-25T22:41:30Z")

</div>

> [@Benoît\_Bouillon](#):
>
> Of course, I didn’t include all the code.

That’s the problem … With just some random lines of code to go on I don’t understand what “What I don’t understand is that my variable is declared as a string” even means. (The obvious answer would be “Because you have declared it as such”.)

---

<div class="post-metadata">

**Author:** ![Benoît\_Bouillon](https://forum.xojo.com/letter_avatar_proxy/v4/letter/b/919ad9/32.png) [@Benoît\_Bouillon](https://forum.xojo.com/u/Beno%C3%AEt_Bouillon)\
**Post date:** [August 25, 2026, 10:47pm UTC](https://forum.xojo.com/t/confusion-between-strings-and-numbers/88794/12 "2026-08-25T22:47:54Z")

</div>

Take a chain “v. 15. → Naniser”  
You split it in order to get Nums(i) and tell me what it happens with the word “Naniser”.

---

<div class="post-metadata">

**Author:** ![Michael\_Hußmann](https://forum.xojo.com/user_avatar/forum.xojo.com/michael_hu%C3%9Fmann/32/438_2.png) [@Michael\_Hußmann](https://forum.xojo.com/u/Michael_Hu%C3%9Fmann)\
**Post date:** [August 26, 2026, 12:14am UTC](https://forum.xojo.com/t/confusion-between-strings-and-numbers/88794/13 "2026-08-26T00:14:01Z")

</div>

Hasn’t this been fully explained already? The string contains representations of numbers and for the purposes of Xojo the substring “15” is the representation of a number, but so is “NaN” (or “Nan” as the comparison is case insensitive) – it is the representation of the Double value you would get by evaluating sqrt(-1), for example. For a similar reason “inf” (infinity) and “-inf” (negative infinity) would be recognized as numbers.

Thus the recommendation to use RegEx and specify a pattern for the kind of numbers you want to be recognized, like strings of digits, possibly including a preceding minus sign and a decimal point. This way you define what counts as a number and what doesn’t.

---

<div class="post-metadata">

**Author:** ![Benoît\_Bouillon](https://forum.xojo.com/letter_avatar_proxy/v4/letter/b/919ad9/32.png) [@Benoît\_Bouillon](https://forum.xojo.com/u/Beno%C3%AEt_Bouillon)\
**Post date:** [August 26, 2026, 12:58am UTC](https://forum.xojo.com/t/confusion-between-strings-and-numbers/88794/14 "2026-08-26T00:58:29Z")

</div>

If I understand correctly, I shouldn’t have asked my question the way I’d already solved it, but I was just intrigued.  
But for me, ‘Naniser’ is neither sqrt(-Naniser), nor ∞(‘Naniser’), nor ∞(‘Naniser’).

---

<div class="post-metadata">

**Author:** ![Julia\_Truchsess](https://forum.xojo.com/user_avatar/forum.xojo.com/julia_truchsess/32/499_2.png) [@Julia\_Truchsess](https://forum.xojo.com/u/Julia_Truchsess)\
**Post date:** [August 26, 2026, 1:22am UTC](https://forum.xojo.com/t/confusion-between-strings-and-numbers/88794/15 "2026-08-26T01:22:16Z")

</div>

Agree, somewhat surprising. I would have expected v to be 0, as it would be with any random string like “foobar”. Some careless coding deep in the bowels of Xojo.

 ![image](https://forum.xojo.com/uploads/default/original/3X/7/c/7c5743d5fc4336aa30d1af7760bef60d1ad54797.jpeg)

 ![image](https://forum.xojo.com/uploads/default/original/3X/8/8/887b858fd1b18d55bd217a8e0fccd55a22d3e8f3.png)

---

<div class="post-metadata">

**Author:** ![Sascha\_S](https://forum.xojo.com/user_avatar/forum.xojo.com/sascha_s/32/22328_2.png) [@Sascha\_S](https://forum.xojo.com/u/Sascha_S)\
**Post date:** [August 26, 2026, 6:35am UTC](https://forum.xojo.com/t/confusion-between-strings-and-numbers/88794/16 "2026-08-26T06:35:37Z")

</div>

> [@Benoît\_Bouillon](#):
>
> What I don’t understand is that my variable is declared as a string.

Still untested code:

```auto
Var extractedNumbers() As Double
Var rx As New RegEx
rx.SearchPattern = "\d+"

Var match As RegExMatch = rx.Search(inputString) // e.g. “v. 15. → Naniser”

While match <> Nil
  extractedNumbers.Add match.SubExpressionString(0).ToDouble // "15"
  match = rx.Search()
End While

```

---

<div class="post-metadata">

**Author:** ![Sascha\_S](https://forum.xojo.com/user_avatar/forum.xojo.com/sascha_s/32/22328_2.png) [@Sascha\_S](https://forum.xojo.com/u/Sascha_S)\
**Post date:** [August 26, 2026, 10:49am UTC](https://forum.xojo.com/t/confusion-between-strings-and-numbers/88794/17 "2026-08-26T10:49:49Z")

</div>

> [@Julia\_Truchsess](#):
>
> Agree, somewhat surprising. I would have expected v to be 0, as it would be with any random string like “foobar”. Some careless coding deep in the bowels of Xojo.

I assume this is intentional by Xojo, because it’s [mentioned in the docs](https://documentation.xojo.com/api/text/val.html#notes):

> Val returns zero if the string contains no numbers, except in the special case where the string begins with the string “NAN”. In this case, it returns “NAN(021)”.

But I agree with you to the extent that an NaN should only be recognized if it is written as “NaN”, followed by no letter…

---

<div class="post-metadata">

**Author:** ![Sascha\_S](https://forum.xojo.com/user_avatar/forum.xojo.com/sascha_s/32/22328_2.png) [@Sascha\_S](https://forum.xojo.com/u/Sascha_S)\
**Post date:** [August 26, 2026, 11:29am UTC](https://forum.xojo.com/t/confusion-between-strings-and-numbers/88794/18 "2026-08-26T11:29:25Z")

</div>

A RegEx i [posted in another Thread](https://forum.xojo.com/t/deleting-non-numeric-characters-from-a-string/88799/4), may be a bit better suited for your needs:

```auto
Var sourceText As String = "v. 15.4 → Naniser 12 8.333"
Var myDouble() As Double

Var rx As New RegEx
rx.SearchPattern = "(?mi-Us)\d+([.,]\d+)?"

Var rxOptions As RegExOptions = rx.Options
rxOptions.MatchEmpty = False
rxOptions.StringBeginIsLineBegin = False
rxOptions.StringEndIsLineEnd = False

Var match As RegExMatch = rx.Search( sourceText )
While match IsA RegExMatch
  
  myDouble.Add match.SubExpressionString(0).ToDouble
  
  match = rx.Search // Fetch the next match
Wend

```

This one extracts multiple decimals from any string.

---

<div class="post-metadata">

**Author:** ![Michael\_Hußmann](https://forum.xojo.com/user_avatar/forum.xojo.com/michael_hu%C3%9Fmann/32/438_2.png) [@Michael\_Hußmann](https://forum.xojo.com/u/Michael_Hu%C3%9Fmann)\
**Post date:** [August 26, 2026, 11:33am UTC](https://forum.xojo.com/t/confusion-between-strings-and-numbers/88794/19 "2026-08-26T11:33:10Z")

</div>

> [@Benoît\_Bouillon](#):
>
> But for me, ‘Naniser’ is neither sqrt(-Naniser), nor ∞(‘Naniser’), nor ∞(‘Naniser’).

Sure it isn’t that, and nobody suggested otherwise. Rather the string gets interpreted as “Nan” (which is the representation of a number in Xojo even though it is “NaN”, i.e. “Not a Number”) followed by “iser” (which even Xojo doesn’t regards as a number).

---

<div class="post-metadata">

**Author:** ![Michael\_Hußmann](https://forum.xojo.com/user_avatar/forum.xojo.com/michael_hu%C3%9Fmann/32/438_2.png) [@Michael\_Hußmann](https://forum.xojo.com/u/Michael_Hu%C3%9Fmann)\
**Post date:** [August 26, 2026, 11:38am UTC](https://forum.xojo.com/t/confusion-between-strings-and-numbers/88794/20 "2026-08-26T11:38:22Z")

</div>

> [@Sascha\_S](#):
>
> But I agree with you to the extent that an NaN should only be recognized if it is written as “NaN”, followed by no letter…

You mean a possible representation of a number must be separated from non-number content by whitespace? But in that case “123abc” wouldn’t be regarded as containing the number 123 either. Or should it be just “NaN”, “INF”, and “-INF” that must be separated by whitespace?

---

<div class="post-metadata">

**Author:** ![Sascha\_S](https://forum.xojo.com/user_avatar/forum.xojo.com/sascha_s/32/22328_2.png) [@Sascha\_S](https://forum.xojo.com/u/Sascha_S)\
**Post date:** [August 26, 2026, 11:51am UTC](https://forum.xojo.com/t/confusion-between-strings-and-numbers/88794/21 "2026-08-26T11:51:02Z")

</div>

> [@Michael\_Hußmann](#):
>
> Or should it be just “NaN”, “INF”, and “-INF” that must be separated by whitespace?

This 🙂

[Next page](https://forum.xojo.com/t/confusion-between-strings-and-numbers/88794.md?page=2)
