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
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(",", "")
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