Solved

Trim a field and check for trimmed value

Posted on 2006-12-01
9
240 Views
Last Modified: 2010-04-23
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
Comment
Question by:TimSweet220
  • 6
  • 3
9 Comments
 
LVL 10

Expert Comment

by:Kinger247
Comment Utility
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
 
LVL 35

Expert Comment

by:YZlat
Comment Utility
Tim, you can use trim function to trim empty spaces not to manipulate the string
0
 
LVL 35

Expert Comment

by:YZlat
Comment Utility
try using Right() function:

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

 DoStuf()
end If
0
 
LVL 35

Expert Comment

by:YZlat
Comment Utility
sorry, I mean Left():

try using Right() function:

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

 DoStuf()
end If
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 35

Accepted Solution

by:
YZlat earned 500 total points
Comment Utility
or

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

end if
0
 
LVL 35

Expert Comment

by:YZlat
Comment Utility
Substring will work too:

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

end if
0
 
LVL 10

Expert Comment

by:Kinger247
Comment Utility
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
 
LVL 35

Expert Comment

by:YZlat
Comment Utility
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
 
LVL 10

Expert Comment

by:Kinger247
Comment Utility
probably be 3 seconds ... ;)  
otheriwse I would have seen it.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now