very difficult for me... get string in string

User avatar
sal21
GoldLounger
Posts: 3437
Joined: 26 Apr 2010, 17:36

very difficult for me... get string in string

Post by sal21 »

VALORE="03-03-2021_103-FATTURA ABDFKKK-.JH89.XLS"

i need to get a 2 part of string.

DATA="03-03-2021"
NR="103"
NOME="FATTURA ABDFKKK-.JH89.XLS"

VALORE, DATA, NOME and NR As dmensioned String

NOME and NR can have dinamic lenght

note:
FATTURA is a fixed part of file the rest of name are dinamic

YasserKhalil
PlatinumLounger
Posts: 4390
Joined: 31 Aug 2016, 09:02

Re: very difficult for me... get string in string

Post by YasserKhalil »

Try this

Code: Select all

Sub Test()
    Dim x, VALORE As String
    VALORE = "03-03-2021_103-FATTURA ABDFKKK-.JH89.XLS"
    x = Split(VALORE, "_")
    Debug.Print "Date: " & x(0)
    Debug.Print "NR: " & Split(x(1), "-")(0)
    Debug.Print "NOME: " & Split(x(1), "-")(1) & "-" & Split(x(1), "-")(2)
End Sub

User avatar
HansV
Administrator
Posts: 70538
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: very difficult for me... get string in string

Post by HansV »

Or:

Code: Select all

    Dim POS1 As Long
    Dim POS2 As Long
    VALORE = "03-03-2021_103-FATTURA ABDFKKK-.JH89.XLS"
    POS1 = InStr(VALORE, "_")
    DATA = Left(VALORE, POS1 - 1)
    POS2 = InStr(POS1 + 1, VALORE, "-")
    NR = Mid(VALORE, POS1 + 1, POS2 - POS1 - 1)
    NOME = Mid(VALORE, POS2 + 1)
Regards,
Hans

User avatar
sal21
GoldLounger
Posts: 3437
Joined: 26 Apr 2010, 17:36

Re: very difficult for me... get string in string

Post by sal21 »

Hans, YasserKhalil
Excellent!

Also to understand me:-)