Link to home
Start Free TrialLog in
Avatar of TimSweet220
TimSweet220

asked on

Trim a field and check for trimmed value

I have a field in a vb.net app  that I need to check part of it to see what it contains.

Can I use the TRIM function to cut out all be the first three charactors or should it be LEN

sample

IF  trim(field1, 3) = "IMG" then

 DoStuf()
end If

Thanks in advance
Avatar of Kinger247
Kinger247

Hi TimSweet220, use the Substring command like:

        Dim Field1 As String = "IMGX1"

        Dim Trimmed As String = Field1.Substring(3)

        Debug.Print(Trimmed)

        'Will display = X1
Avatar of YZlat
Tim, you can use trim function to trim empty spaces not to manipulate the string
try using Right() function:

IF  Right(field1, 3) = "IMG" then

 DoStuf()
end If
sorry, I mean Left():

try using Right() function:

IF  Left(field1, 3) = "IMG" then

 DoStuf()
end If
ASKER CERTIFIED SOLUTION
Avatar of YZlat
YZlat
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Substring will work too:

If field1.Substring(0, 3) ="IMG" then

end if
ah, you wanted the first 3 characters ...

        Dim Field1 As String = "IMGX1"

        Dim Trimmed As String = Field1.Substring(0, 3)

        Debug.Print(Trimmed)

        'Will display = IMG

@YZlat : 'Left' isn't strictly .net though is it ...
well, I gave other examples too, in case Left won't work for him.

By the way, in your last example you repeated what I've said already...
probably be 3 seconds ... ;)  
otheriwse I would have seen it.