• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 419
  • Last Modified:

Replace period or comma in statement

I have been trying to add in functionality to have this statment replace periods as well but can't get the syntax correct.  How can I replace commas and periods

Private Function formatPay(ByVal thePay As Double) As String
        Dim formattedPay = Replace(CStr(FormatNumber(thePay, 2)), ",", "")

        Do While Len(formattedPay) < 11
            formattedPay = "0" & formattedPay
        Loop

        formatPay = formattedPay
    End Function
0
kdeutsch
Asked:
kdeutsch
  • 3
  • 2
1 Solution
 
Pratima PharandeCommented:
No sure got your question
did you mean to say you want to replace th period

with space

 Dim formattedPay As String = FormatNumber(thePay, 2).ToString().Replace(".", "")

with comma

 Dim formattedPay As String = FormatNumber(thePay, 2).ToString().Replace(".", ",")
0
 
Éric MoreauSenior .Net ConsultantCommented:
try this:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MessageBox.Show(formatPay(1234.56))
    End Sub

    Private Function formatPay(ByVal thePay As Double) As String
        'Dim formattedPay = Replace(CStr(FormatNumber(thePay, 2)), ",", "")

        'Do While Len(formattedPay) < 11
        '    formattedPay = "0" & formattedPay
        'Loop

        'formatPay = formattedPay
        Return (thePay * 100).ToString("00000000000")
    End Function
0
 
kdeutschAuthor Commented:
All,

I need the statement to replace periods and comma's not just one or the other, I need both replaced.

I don't have a buttonclick that handles these events, it is a file that writes directly to a text file.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Éric MoreauSenior .Net ConsultantCommented:
>>I don't have a buttonclick that handles these events

it is only an example to test!

You can also try:
   Private Function formatPay(ByVal thePay As Double) As String
        Dim formattedPay = thePay.tostring("000000000.00").replace(".","").replace(",", "")

        Return formattedPay
    End Function
0
 
kdeutschAuthor Commented:
emoreau,
I see what was happening, ok both your solutions work, thanks.
0
 
kdeutschAuthor Commented:
Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now