943,852 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 58892
  • VB.NET RSS
Jul 10th, 2007
0

How do I delete the last character of a string

Expand Post »
I am a beginner in VB. I am trying to make a simple unit converter. Can please some body tell me how can I delete the last character of the number I enter in my inputbox?

thank you
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
shoebodh is offline Offline
1 posts
since Jul 2007
Jul 11th, 2007
0

Re: How do I delete the last character of a string

Take input as a string. Chop of the last character, then convert string to number.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jul 11th, 2007
1

Re: How do I delete the last character of a string

I assume you are putting your input to a textbox. So try this:
VB.NET Syntax (Toggle Plain Text)
  1. TextBox1.Text = InputBox("Enter number")
  2. TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 1)
Reputation Points: 84
Solved Threads: 58
Posting Pro in Training
waynespangler is offline Offline
461 posts
since Dec 2002
Feb 21st, 2008
0

Re: How do I delete the last character of a string

Click to Expand / Collapse  Quote originally posted by shoebodh ...
I am a beginner in VB. I am trying to make a simple unit converter. Can please some body tell me how can I delete the last character of the number I enter in my inputbox?

thank you
You also could use the IsNumeric(TextboxName.Text) Then
TextboxName.Text.Length -1 as the other poster stated which will subtract the last number in the textbox
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
SolTec is offline Offline
65 posts
since Jan 2008
Feb 21st, 2008
0

Re: How do I delete the last character of a string

VB.NET Syntax (Toggle Plain Text)
  1. Dim str As string
  2. str = "Ramy1"
  3. str = str.Remove(str.Length - 1);
  4. ' str = Ramy
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006
Feb 21st, 2008
0

Re: How do I delete the last character of a string

i think wayne already answered this thread.
Last edited by Jx_Man; Feb 21st, 2008 at 11:25 pm.
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,140 posts
since Nov 2007
Feb 22nd, 2008
0

Re: How do I delete the last character of a string

Yes yes thanks JX
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006
Jun 28th, 2011
-1
Re: How do I delete the last character of a string
I need to remove the last ",-1,-1,-1" from this line


'XXXXXX XXXX `XXXXXXXXXXXX` XXXXX (XXXX,'XX','XXXX','YYYY YYY YYYYYY YYYYY YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY YYYYYYYYYYYYYYYYYYY.',Y,'YYYYY YY YYYY YYY YYYY XX.XX',X,X,-1,-1,-1)'
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dhanalakahmi s is offline Offline
1 posts
since Jun 2011
Jun 29th, 2011
0
Re: How do I delete the last character of a string
Is that a specific example of a more general case?. For example, if the last three fields are always -1,-1,-1 then you just need to replace ",-1,-1,-1)" with ")". However, if the last three fields can take on other values then one solution would be a loop that would look for the last "," and strip off the last field. You could do (for example):

VB.NET Syntax (Toggle Plain Text)
  1. Private Function StripLast(ByVal flds As String, ByVal numflds As Integer) As String
  2.  
  3. Do While numflds > 0
  4. flds = flds.Substring(0, flds.LastIndexOf(","))
  5. numflds -= 1
  6. Loop
  7.  
  8. Return flds & ")"
  9.  
  10. End Function

will return the string with the last given number of fields stripped off. Sample call is:

VB.NET Syntax (Toggle Plain Text)
  1. flds = "YYYYYYYYYYYYYYYYYYY.',Y,'YYYYY YY YYYY YYY YYYY XX.XX',X,X,-1,-1,-1)"
  2. flds = StripLast(flds,3)
  3.  
  4. 'flds now has the value "YYYYYYYYYYYYYYYYYYY.',Y,'YYYYY YY YYYY YYY YYYY XX.XX',X,X)"

Is this what you intended?
Last edited by Reverend Jim; Jun 29th, 2011 at 11:17 am.
Reputation Points: 144
Solved Threads: 101
Master Poster
Reverend Jim is offline Offline
769 posts
since Aug 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Display datagrid results on page while exporting to xls
Next Thread in VB.NET Forum Timeline: vb.net connection string of ms access database in sharepoint





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC