Home javascript android java php c# ubuntu python c++ c ios TAGS

Find a specific number in a string


Date : 2019-06-06 19:05:05 , By : Nathan Land

I'm using an IF THEN statement to determine if a string contains a specific number. For example, the string = 1, 9, 13. I'm trying to isolate strings that contain the single number "3". However, when I use Like "3", or Like "3", I also get the results back that contain 13. How do I use wildcards to do this?

TAGS : vba
Answers :
By : Ben

If your string is just a list of numbers in the form you have shown ... "n1, n2, n3, n4"

... then you can use VBA's Like function as follows:

Debug.Print " 1, 7, 5, 13," Like "*[ ]3,*" 'matches 3 but not 13

If your string is arbitrary, then this is actually a regular expression question, and you'll need to decide if this a route you want to go down. Something like the following works at the Regex Tester Page:

/\b3\b/g

There's a useful VBA Regex Regular Expressions Guide which shows you how to use syntax like this, including how to set a reference to the additional library that you need for it to work.

- Technology - Yellow pages
» java
» php
» c#
» ubuntu
» python
» c++
» c
» ios
» jquery
» html
» sql
» r
» mysql
» linux
» access
» iphone
» css
» excel
» vb.net
» .net
» ruby
Privacy Policy - Copyrights Notice - Terms - Contact Us 2019 © tinytut
Licensed under cc by-sa 3.0 with attribution required.