I have a filename in a string. I want to split the given string into 2 (1 is filename without extension, 2 is only extension) strings. Then add _dev
to the end of first string开发者_Python百科 and concatenate with 2nd one.
ex:
Dim name as string="abc.txt"
Dim finalName as string
The finalName
should be like this "abc_dev.txt"
Any suggestions please?
If they're really filenames:
' unested, likely to contain spelling errors
name = Path.GetFileNameWithoutExtension(oldName)
ext = Path.GetExtension(oldName)
newName = odlName & "_dev"
newName = Path.ChangeExtension(newName, ext)
How about
finalName = Path.GetFileNameWithoutExtension(name) & "_dev" & Path.GetExtension(name)
Try the following:
Dim newName as String = oldName.Insert(oldName.LastIndexOf("."), "_dev")
Refer to:
String.Insert Method
String.IndexOf Method (String)
String.LastIndexOf Method (String)
精彩评论