Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VBNET
Expertise: beginner
Jan 5, 2002

Trimming strings

Visual Basic .NET strings expose three trim methods: TrimStart, TrimEnd, and Trim - which trim one or more characters from the beginning, the end, or both the beginning and end of the string. They therefore work like VB6's LTrim, RTrim, and Trim functions, with an important difference: you can decide which characters are to be trimmed. For example, in many cases you want to trim not just spaces, but also tabs and CR-LF pairs. Here's the compact VB.NET solution:

' S is the string to be trimmed.
Dim cArr() As Char = { " "c, Chr(9), Chr(13), Chr(10) }
s = s.TrimStart(cArr)
You can use the same pattern with TrimEnd and Trim, of course.
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap