Solved

Trim a field and check for trimmed value

Posted on 2006-12-01
9
244 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 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