• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

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
0
TimSweet220
Asked:
TimSweet220
  • 6
  • 3
1 Solution
 
Kinger247Commented:
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
0
 
YZlatCommented:
Tim, you can use trim function to trim empty spaces not to manipulate the string
0
 
YZlatCommented:
try using Right() function:

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

 DoStuf()
end If
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
YZlatCommented:
sorry, I mean Left():

try using Right() function:

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

 DoStuf()
end If
0
 
YZlatCommented:
or

If Mid(field1,1, 3) ="IMG" then

end if
0
 
YZlatCommented:
Substring will work too:

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

end if
0
 
Kinger247Commented:
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 ...
0
 
YZlatCommented:
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...
0
 
Kinger247Commented:
probably be 3 seconds ... ;)  
otheriwse I would have seen it.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now