C# 子串 : Removing first three characters

标签 c# string substring

我有一个字符串,我想从中删除前三个字符。我该如何使用子字符串来解决这个问题,或者还有其他方法吗?

string temp = "01_Barnsley"
string textIWant = "Barnsley"

谢谢

最佳答案

您可以使用 String.Substring(Int32) method .

Retrieves a substring from this instance. The substring starts at a specified character position and continues to the end of the string.

string textIWant = temp.Substring(3);

这是一个 demonstration .

作为替代方案,您可以使用 String.Remove method(Int32, Int32) method还有。

Returns a new string in which a specified number of characters in the current instance beginning at a specified position have been deleted.

string textIWant = temp.Remove(0, 3);

这是一个 demonstration .

关于C# 子串 : Removing first three characters,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21909132/

相关文章:

c# - Entity Framework 5 DbUpdateException : Null value for non-nullable member

c++ - 检查字符串是否重复出现特定字符

java - 如何打印单个索引?

java - 子串索引范围

Java:带有长类型参数的 String.substring()

c# - 使用 Redis 与仅使用 Redis 的 NHibernate 二级缓存

c# - 从我正在迭代的列表中删除项目,或过滤复杂的重复列表

c# - 满足此要求的 WPF 控件或方法是什么?

c++ - 使用 std::equal_range 查找出现在字符串 vector 中的前缀范围

python - 编写一个函数,通过添加字符以某种方式修改某个字符串