i have this string:
asdds asdasdasd asdasdsad aasdddddd EURO 53,000 D
ssssss aaaaas eeee EURO 53,000 D
i need to get the trimmed value between EURO and D
note:
The lenght of string is variable... but into the string are present always EURO and D
GET value into the string
-
- Administrator
- Posts: 78561
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: GET value into the string
Let's say the string is named strValue.
' Declare variables
Dim p1 As Long
Dim p2 As Long
Dim strReturn As String
' Find position of "EURO"
p1 = InStr(strValue, "EURO")
' Find position of "D" after "EURO"
p2 = InStr(p1 + 4, strValue, "D")
' Extract value
strReturn = Mid(strValue, p1 + 4, p2 - p1 - 4)
' Trim the string
strReturn = Trim(strReturn)
' Declare variables
Dim p1 As Long
Dim p2 As Long
Dim strReturn As String
' Find position of "EURO"
p1 = InStr(strValue, "EURO")
' Find position of "D" after "EURO"
p2 = InStr(p1 + 4, strValue, "D")
' Extract value
strReturn = Mid(strValue, p1 + 4, p2 - p1 - 4)
' Trim the string
strReturn = Trim(strReturn)
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4364
- Joined: 26 Apr 2010, 17:36
Re: GET value into the string
strugged arround 2 days!!!!!!!!!!!!!!!!!!!!!!HansV wrote:Let's say the string is named strValue.
' Declare variables
Dim p1 As Long
Dim p2 As Long
Dim strReturn As String
' Find position of "EURO"
p1 = InStr(strValue, "EURO")
' Find position of "D" after "EURO"
p2 = InStr(p1 + 4, strValue, "D")
' Extract value
strReturn = Mid(strValue, p1 + 4, p2 - p1 - 4)
' Trim the string
strReturn = Trim(strReturn)
Now with Hans anly a minutes! tath is very good
but.... i can use this similar function or to speed up the code i can incapsulate into the code?
Note:
The string is a result of loop from txt file with approx 45.xxx lines
-
- Administrator
- Posts: 78561
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: GET value into the string
You can use this code within other code, of course, but I don't know whether it will speed up that code - that depends on what you're currently doing with the lines.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4364
- Joined: 26 Apr 2010, 17:36
Re: GET value into the string
OK! i thinking and decide....HansV wrote:You can use this code within other code, of course, but I don't know whether it will speed up that code - that depends on what you're currently doing with the lines.
-
- PlatinumLounger
- Posts: 4364
- Joined: 26 Apr 2010, 17:36
Re: GET value into the string
PROB!HansV wrote:Let's say the string is named strValue.
' Declare variables
Dim p1 As Long
Dim p2 As Long
Dim strReturn As String
' Find position of "EURO"
p1 = InStr(strValue, "EURO")
' Find position of "D" after "EURO"
p2 = InStr(p1 + 4, strValue, "D")
' Extract value
strReturn = Mid(strValue, p1 + 4, p2 - p1 - 4)
' Trim the string
strReturn = Trim(strReturn)
"D" is dinamic is possible ican have DD, C ...
EURO is static
Note:
Explain me +4 and -4
tks for patience
-
- Administrator
- Posts: 78561
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: GET value into the string
The +4 is the length of the string "EURO". We have to add this to the position of the string to find the text after it.
Will there always be a space between the number and the letter(s) after it?
Will there always be a space between the number and the letter(s) after it?
Best wishes,
Hans
Hans