5 Replies - 205 Views - Last Post: 27 September 2019 - 06:29 AM Rate Topic: -----

#1 Interplain   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 02-November 16

String adding a extra zero to a 3 digit number

Posted 27 September 2019 - 04:02 AM

Hi, could someone help me with this please. I have a string and in this string is a word "Size" what i am trying to do is change the word size in to a number. This works for some numbers but if i put 500 in it adds an extra zero to the end making it 5000. It will replace size with other numbers and randomly not work.

        Dim OldString = LblDimensions.Text
        Dim WithNewValue As String = TxtEditMtrs.Text
        Dim NewString As String = OldString.Replace("Size", WithNewValue)
        LblDimensions.Text = NewString




Original format of the string is: Vinyl Size *1.06m * 1.5mm

I use a textbox with WithNewValue to replace the word Size, how do i replace it with only the new string please.

i have tried Regex but cant do it with that. does the same.

thank you

Is This A Good Question/Topic? 0
  • +

Replies To: String adding a extra zero to a 3 digit number

#2 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6819
  • View blog
  • Posts: 28,250
  • Joined: 12-December 12

Re: String adding a extra zero to a 3 digit number

Posted 27 September 2019 - 05:32 AM

Looks like it should work, does the code actually execute? Put a breakpoint in there or, at least, throw up a MessageBox to confirm that it runs.
Was This Post Helpful? 1
  • +
  • -

#3 maceysoftware   User is offline

  • Member Title
  • member icon

Reputation: 383
  • View blog
  • Posts: 1,630
  • Joined: 07-September 13

Re: String adding a extra zero to a 3 digit number

Posted 27 September 2019 - 05:43 AM

Works fine for me.

I have done it slightly different to yourself but without really changing anything you have done at the same time.

I have a form with 2 labels, 1 textbox and a button.

Labels called:

LabelOriginalString - Text = "Vinyl Size *1.06m * 1.5mm"
LabelNewString - Text = ""

Whenever I press the button it will take what is in the LabelOriginalString.Text, replace the word size with what is in the textbox and present it in LabelNewString.

LabelNewString.Text = LabelOriginalString.Text.Replace("Size", TextBoxSizeValue.Text)



The two differences with my code and yours is:

1) I made my code shorter, I don't need to store strings into another string variable before working with it.
2) I set the replaced string to be in a different label instead of putting it in the same label, so you could see the before and after.
Was This Post Helpful? 1
  • +
  • -

#4 Interplain   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 02-November 16

Re: String adding a extra zero to a 3 digit number

Posted 27 September 2019 - 05:55 AM

I figured it, and Thanks to you both. nothing wrong with my code. It was because i have some other code that was going over the the same string and adding another number on it. And maceysoftware your code is the best way Thanks for that loads easier.

This post has been edited by andrewsw: 27 September 2019 - 06:01 AM
Reason for edit:: removed previous quote

Was This Post Helpful? 0
  • +
  • -

#5 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6819
  • View blog
  • Posts: 28,250
  • Joined: 12-December 12

Re: String adding a extra zero to a 3 digit number

Posted 27 September 2019 - 06:01 AM

@OP Note that you do not have to quote the previous post in full, there is a Reply button further down the page.
Was This Post Helpful? 0
  • +
  • -

#6 Interplain   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 02-November 16

Re: String adding a extra zero to a 3 digit number

Posted 27 September 2019 - 06:29 AM

Okay got it Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1