Split file name from the String

How to split specific file name from string.
for e.g C:\Users\DEEP\Desktop\IDM\zip\ExcelCompare\04-12-2018.xlsx

it is the string and i want to extract the date from here only

1 Like

variable.ToString.Split("".ToCharArray)(7)

@Sandeep_Kumar2

You can use vb.net functions to get filename from an path without extenstion

path.GetFileNameWithoutExtension("C:\Users\DEEP\Desktop\IDM\zip\ExcelCompare\04-12-2018.xlsx")

3 Likes

Hey @Sandeep_Kumar2

Just Use Path.GetFileName(“C:\Users\DEEP\Desktop\IDM\zip\ExcelCompare\04-12-2018.xlsx”).

Regards…!!
Aksh

3 Likes

index was outside the bound of array

forward slash is not showing inside double quotes. variable.ToString.Split(“forward slash”.ToCharArray)(7)

what if i just only wanna get name not extension

Use this -

Path.GetFileNameWithoutExtension(“C:\Users\DEEP\Desktop\IDM\zip\ExcelCompare\04-12-2018.xlsx”)

This Will be helpful in all cases and not dependent on file path length :slight_smile:

Regards…!!
Aksh

2 Likes

(“C:\Users\DEEP\Desktop\IDM\zip\ExcelCompare\04-12-2018.xlsx”).ToString.Split(“forward slash”.ToCharArray)(7).Split(".".ToCharArray)(0)

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.