gpt4 book ai didi

c# - 在字符串中插入字符串

转载 作者:行者123 更新时间:2023-11-30 13:32:17 25 4
gpt4 key购买 nike

我在字符串中插入子字符串时遇到问题我想要的是将 "/thumbs" 注入(inject)字符串路径

/media/pictures/image1.jpg

我想像这样将/thumbs/注入(inject)路径的最后一部分:

/media/pictures/thumbs/image1.jpg

用 linq 可以吗?

最佳答案

对于路径操作之类的东西,最好使用 System.IO 命名空间,特别是 Path 对象。你可以做类似的事情;

string path = "/media/pictures/image1.jpg";
string newPath = Path.Combine(Path.GetDirectoryName(path), "thumbs", Path.GetFileName(path)).Replace(@"\", "/");

关于c# - 在字符串中插入字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14944845/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com