VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



A Function that removes all of a chr from a string

by Steve (12 Submissions)
Category: String Manipulation
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (5 Votes)

This is a fairly basic code, but I had someone ask me how to do it, so I figured since I made it I might as well post it. Basicly this is a simple function which you can add to either a bas, or a form, and then you call it, and it removes all occurenses of a character within a string. IE.(My name is steve) if you wanted to remove all the spaces you could use this.

API Declarations
'Check out my website at http://www.vbtutor.com
'Thanks

Rate A Function that removes all of a chr from a string

Function RemoveChar(sText As String, sChar As String) As String
  Dim iPos As Integer, iStart As Integer
  Dim sTemp As String
  iStart = 1
  Do
    iPos = InStr(iStart, sText, sChar)
    If iPos <> 0 Then
      sTemp = sTemp & Mid(sText, iStart, (iPos - iStart))
      iStart = iPos + 1
    End If
  Loop Until iPos = 0
  sTemp = sTemp & Mid(sText, iStart)
  RemoveChar = sTemp
End Function

'The code could then be called like this
Call RemoveChar(Text1.text, " ")
'This will rmove all the spaces from the textbox
'named Text1
'I hope this helps some people out. I have actualy
'surprisignly enought had 37 requests from visitors
'to my site for this code.

Download this snippet    Add to My Saved Code

A Function that removes all of a chr from a string Comments

No comments have been posted about A Function that removes all of a chr from a string. Why not be the first to post a comment about A Function that removes all of a chr from a string.

Post your comment

Subject:
Message:
0/1000 characters