Trim all Nonprinting Characters from a String (VB5/VB6/.NET)

Category:
String Manipulation
Type:
Snippets
Difficulty:
Beginning
Author:
Intelligent Solutions Inc.

Version Compatibility: Visual Basic 6, Visual Basic 5, Visual Basic.NET

More information:
VB's Trim function only trims space characters (" ") from the beginning or the end of a string. This alternative trims all nonprinting characters (tabs, character returns, etc.)

Small revisions applied 3/31/03 allow function to work correctly in VB.NET as well.

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code: