Skip to Content
author's profile photo Former Member
Former Member

matrix read out numbers only - VB.Net code sample

Hi all,

instead of asking yet another question, I would like to publish a helpful bit of code as solution to a problem concerning the matrix item.


When reading out specific cells containing currency values, SBO returns a string including the currency. (ie "1.000,95 EUR") This value obviously cannot be casted into a double value.

Here is a code snippet which takes care of the issue. Glad for any comments on this.

HTH Lutz Morrien

Public Class NumbersInStr

Public Shared Function AsString(ByVal StringToFilter As String) As String

' This function takes a string as input and filters out all chars

' which do not appear in the string GoodChars

' Example: Input "220,00 EUR"

' Output "220,00"

Dim intCharCount As Integer

Dim GoodChars As String

Dim strResult As String

'if using english format, replace "," by "."

GoodChars = "12345677890,"

'go through string

For intCharCount = 0 To StringToFilter.Length - 1

'if char at current location is a "good char",

' then move it to result string

If GoodChars.IndexOf(StringToFilter.Chars(intCharCount)) >= 0 Then

strResult = strResult & StringToFilter.Chars(intCharCount)

End If


If strResult <> "" Then

Return strResult


Return "0"

End If

End Function

Public Shared Function AsDouble(ByVal MixedString As String) As Double

Return CDbl(AsString(MixedString))

End Function

Public Shared Function AsSingle(ByVal MixedString As String) As Single

Return CSng(AsString(MixedString))

End Function

End Class

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Jan 27, 2004 at 04:30 PM

    it is too complecated for me.

    why don't you use System.Text.RegularExpressions.Regex object ?

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Lutz, here you are (C# example) :

      double val = 0.0;

      string rexp = "(?[0-9-])(?<val>[0-9-.,])(?[^0-9]*)";

      string inp = "eur -1.000,95 EUR";

      System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(rexp);

      System.Text.RegularExpressions.Match m = r.Match(inp);


      val = Convert.ToDouble(m.Groups["val"].Value.Replace("." , ""));


      have a good time, greetings from Poland


Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.