开发者

How to split and concatenate a string

开发者 https://www.devze.com 2023-03-09 19:36 出处:网络
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 con

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)


0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号