Make More Versatile Trim Functions

One of the nice things about VB is the ability to redefine most of the built-in commands. For example, you can extend the functionality of the Trim family of commands. LTrim and RTrim remove leading and trailing spaces from a string, but it also would be useful to remove other nonprinting characters, such as tabs, or carriage return/line feed pairs that might be present after reading in a text file. This code does exactly that by removing all leading and trailing characters with an ASCII value less than or equal to that of a space character:

 Public Function Trim(ByVal inString As String) _	As String	Trim = RTrim(LTrim(inString))End FunctionPublic Function RTrim(ByVal inString As String) _	As String	Dim nPos As Long	nPos = Len(inString)	If nPos > 0 Then		Do While (Asc(Mid$(inString, _			nPos, 1)) <= 32)			nPos = nPos - 1			If nPos = 0 Then Exit Function		Loop		RTrim = Left$(inString, nPos)	End IfEnd FunctionPublic Function LTrim(ByVal inString As String) _	As String	Dim nPos As Long, nLen As Long	nLen = Len(inString)	If nLen > 0 Then		nPos = 1		Do While Asc(Mid$(inString, nPos, 1)) <= 32			nPos = nPos + 1			If nPos = nLen Then Exit Function		Loop		LTrim = Mid$(inString, nPos)	End IfEnd Function
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS