Click here to Skip to main content
15,896,348 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everyone,

I have an issue in VB.NET

I have string array.That array contains strings having spaces bothsides(left and right).How do i remove spaces.I am putting string in Datarow.

I am doing like this,but its trimming right side.I want to trim left side also.
Please help me out.

Dim EachLineData() As String = Split(sLine, sCharSep)


dataRw(iCol) = EachLineData(iCol).ToString.PadRight(aColLen(iCol) + 1).Remove(aColLen(iCol)).TrimEnd
Posted
Comments
Sergey Alexandrovich Kryukov 10-Aug-12 17:54pm    
Do you ever read MSDN help?
--SA

use only 'Trim' to remove extra spaces from both side, 'TrimEnd' will remove only right-side extra spacing

eg.
VB
dim str as String = "  aaa  ";
          str = str.Trim();

Happy Coding!
:)
 
Share this answer
 
Comments
Volynsky Alex 10-Aug-12 5:44am    
Good answer aarti meswania !
Aarti Meswania 10-Aug-12 5:45am    
thank you! :)
Volynsky Alex 10-Aug-12 6:15am    
You are welcome
DileepkumarReddy 10-Aug-12 6:22am    
Thanx for the help..
Aarti Meswania 10-Aug-12 8:57am    
welcome :)
Check this once

VB
YourString.Left(YourString.Length-4)
 
Share this answer
 
v2
VB
Dim str As String = "   mm   aaa   dd     "
 str = str.Replace(" ", "")
 str = str.Trim()
 
Share this answer
 
v2
Comments
Joan M 10-Aug-12 9:42am    
Wouldn't the call to "str = str.Trim()" be completely avoidable?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900