2

I have this problem in split

I want to convert the numeric into formatcurrency but it contains a Character

For example:

POC 1900
output :
POC $1,900.00

Or

    1900 POC 
    output :
    $1,900.00 POC

Thank you

4

2 回答 2

1

Use Regular Expression to match and replace values.

Dim str = "1900 POC" //Or "POC 1900"
Dim reg = New Regex("\d+")

Dim match = reg.Match(str)
If match.Success Then
  str = reg.Replace(str, Decimal.Parse(match.Value).ToString("C"))
  Console.WriteLine(str)
End If

EDIT:

If string contains comma (,) between numbers then replace it with :

Dim str = "1,900 POC".Replace(",", "")
于 2012-12-27T03:30:31.403 回答
0
Dim strValue As String = "POC 1900"
Dim strOutput As String = String.Empty
Dim strNum As String() = strValue .Split(" ")
Dim strDisplay As String = String.Empty
For x As Integer = 0 To strNum.Length - 1
   strDisplay = String.Concat(strDisplay, " ", IIf(IsNumeric(strNum(x)), FormatCurrency(Val(strNum(x)), 2), strNum(x)))
Next

strOutput = strDisplay
于 2012-12-27T02:58:05.173 回答