I have a pdf file named “Others-Contract-20230731” and I split it in 3 section using CurrentFile.Name.Split(“-”). I’m getting First and Last string (In this case, it means “Others” and “20230731”). But how do I get the middle string (“Contract”)?
If there is anyone who knows the solution, please help me.
@balt-ochir.g
StringVar.Split(“-”.ToCharArray)(0) of 0th index
StringVar.Split(“-”.ToCharArray)(1)of 1st index
StringVar.Split(“-”.ToCharArray)(2)of 2nd index
// Assuming CurrentFile.Name contains the filename “Others-Contract-20230731”
// Split the filename using “-” as the separator
splitResult As String() = CurrentFile.Name.Split("-"c)
// Access the middle string (“Contract”) by using the second element (index 1) in the array
middleString As String = splitResult(1)
// Now the “middleString” variable will hold the value “Contract”
Hi, I tried your solution yesterday and it works. Unfortunately I forgot that I have different type of files. Some files are named “Job Description-20230731” and some are “Others-Contract-20230731” as I mentioned. But when I try to get string with CurrentFile.Name.Split(“-”)(1), it gives me correct string when the file is named “Others-Contract-20230731” but when the file is named “Job Description-20230731” it gives me wrong string (20230731). I want to get first string if there is not any middle string? What should I do? Please help me.