?
Solved

Trim a field and check for trimmed value

Posted on 2006-12-01
9
Medium Priority
?
257 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
ID: 18056497
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
ID: 18056541
Tim, you can use trim function to trim empty spaces not to manipulate the string
0
 
LVL 35

Expert Comment

by:YZlat
ID: 18056549
try using Right() function:

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

 DoStuf()
end If
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:YZlat
ID: 18056551
sorry, I mean Left():

try using Right() function:

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

 DoStuf()
end If
0
 
LVL 35

Accepted Solution

by:
YZlat earned 2000 total points
ID: 18056559
or

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

end if
0
 
LVL 35

Expert Comment

by:YZlat
ID: 18056573
Substring will work too:

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

end if
0
 
LVL 10

Expert Comment

by:Kinger247
ID: 18056577
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
ID: 18056600
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
ID: 18056637
probably be 3 seconds ... ;)  
otheriwse I would have seen it.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Loops Section Overview
Suggested Courses

840 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