Solved

Trim a field and check for trimmed value

Posted on 2006-12-01
9
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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 500 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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 …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 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