i can have i MyVar
+1-242-BAHAMAS-(BS).gif
+1-869-SAINT KITTS AND NEVIS-(KN).gif
+591-BOLIVIA-(BO).gif
+39-ITALY-(IT).gif
....
ecc
In effect variuos states have a phone code and sub phone code, else for example, Italy have only a code phone
i need to get the name of state
Note:
the part of (XX).gif if fixed for all
FOR THE WIZARD... get part of string.
-
- PlatinumLounger
- Posts: 4353
- Joined: 26 Apr 2010, 17:36
-
- Administrator
- Posts: 78416
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: FOR THE WIZARD... get part of string.
Mid(MyVar, InStr(MyVar, "(") + 1, InStr(MyVar, ")") - InStr(MyVar, "(") - 1)
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4353
- Joined: 26 Apr 2010, 17:36
-
- Administrator
- Posts: 78416
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: FOR THE WIZARD... get part of string.
Sorry, I misinterpreted your question.
or
Code: Select all
Dim p As Long, q As Long
p = InStrRev(MyVar, "-")
q = InStrRev(MyVar, "-", p - 1)
MsgBox Mid(MyVar, q + 1, p - q - 1)
Code: Select all
Dim v As Variant
v = Split(MyVar, "-")
MsgBox v(UBound(v) - 1)
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4353
- Joined: 26 Apr 2010, 17:36
Re: FOR THE WIZARD... get part of string.
G R E A T!HansV wrote: ↑11 Feb 2022, 13:07Sorry, I misinterpreted your question.
orCode: Select all
Dim p As Long, q As Long p = InStrRev(MyVar, "-") q = InStrRev(MyVar, "-", p - 1) MsgBox Mid(MyVar, q + 1, p - q - 1)
Code: Select all
Dim v As Variant v = Split(MyVar, "-") MsgBox v(UBound(v) - 1)
Tks bro.
-
- 4StarLounger
- Posts: 544
- Joined: 27 Jun 2021, 10:46
Re: FOR THE WIZARD... get part of string.
Might be an entertaining time to introduce regular expressions ...
e,g.
e,g.
Code: Select all
With CreateObject("vbscript.regexp")
.Pattern = "\b([^\d\W])+\b"
MsgBox .Execute(MyVar)(0)
End With
-
- PlatinumLounger
- Posts: 4353
- Joined: 26 Apr 2010, 17:36
Re: FOR THE WIZARD... get part of string.
nice, tksSpeakEasy wrote: ↑11 Feb 2022, 16:09Might be an entertaining time to introduce regular expressions ...
e,g.
Code: Select all
With CreateObject("vbscript.regexp") .Pattern = "\b([^\d\W])+\b" MsgBox .Execute(MyVar)(0) End With
but... i can use the same method to get the phone code from:
i can have i MyVar
+1-242-BAHAMAS-(BS).gif
+1-869-SAINT KITTS AND NEVIS-(KN).gif
+591-BOLIVIA-(BO).gif
+39-ITALY-(IT).gif
....
ecc
and i need:
vaphone="+1-242"
vaphone="+1-869"
vaphone="+591"
vaphone="+39"
...ecc
-
- 4StarLounger
- Posts: 544
- Joined: 27 Jun 2021, 10:46
Re: FOR THE WIZARD... get part of string.
Code: Select all
With CreateObject("vbscript.regexp")
.Pattern = "\+([\d-]+)-"
MsgBox .Execute(MyVar)(0).SubMatches(0)
End With
-
- PlatinumLounger
- Posts: 4353
- Joined: 26 Apr 2010, 17:36
Re: FOR THE WIZARD... get part of string.
Great!SpeakEasy wrote: ↑11 Feb 2022, 18:10Code: Select all
With CreateObject("vbscript.regexp") .Pattern = "\+([\d-]+)-" MsgBox .Execute(MyVar)(0).SubMatches(0) End With
Never used regex, very powerful!