如何从索引处的字符串中删除 [英] How to remove from string at index
本文介绍了如何从索引处的字符串中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎么能将索引从0移除到2
C:\\Folder1 \\Folder2 \\Folder3 \\\\Folder4
我想删除我的字符串中的这个文字C:\\Folder1 \\Folder2 \\
所以索引[0],[1],[1]
并且只显示Folder3 \\ \\\Folder4
how could i remove the index from 0 to 2
C:\\Folder1\\Folder2\\Folder3\\Folder4
I want to remove this text in my string C:\\Folder1\\Folder2\\
So index[0],[1],[1]
And only display Folder3\\Folder4
推荐答案
如果实际文件夹名称未知,您可以进行拆分和连接以实现此目的(使用一点LINQ)...
If the actual folder names are unknown you may do split and join to achieve this (with a bit of LINQ)...
string src = "C:\\Folder1\\Folder2\\Folder3\\Folder4";
string[ ] arr = src.Split( new char[ ] { '\\' } );
arr = arr.Where( ( value, index ) => index > 2 ).ToArray( );
string rv = string.Join( "\\", arr );
使用子字符串:
Use Substring:
string source = "C:\\Folder1\\Folder2\\Folder3\\Folder4";
string prefix = "C:\\Folder1\\Folder2\\";
string result = source.StartsWith(prefix)
? source.Substring(prefix.Length)
: source;
这篇关于如何从索引处的字符串中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文