Solved

Trim a field and check for trimmed value

Posted on 2006-12-01
9
243 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Title # Comments Views Activity
Get Client IP on RDS - VB.NET 15 69
VB.NET 2008 - SQL Timeout 9 34
How do sunrise and sunset times change with altitude 14 38
MYSQL responding very slow 3 23
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

860 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