如何切割我不需要的一部分字符串 [英] How Do I Cut A Part Of String I Dont Need
本文介绍了如何切割我不需要的一部分字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我这里有一个字符串例如
Dim str as String
string =CodeProject
现在我想要一个函数,它将从字符串中删除Project,保留字符串值Code
有关如何执行此操作的任何想法?谢谢
我没有google:)
解决方案
您可以使用正则表达式替换方法。我在c#中给出样本。
使用 System.Text 。常用表达;
字符串 str = CodeProject
Regex rgx = new 正则表达式( < span class =code-string> Project);
string result = rgx.Replace(str, );
您可以使用Sustring方法,
< pre lang =cs> string cs = CodeProject 跨度>;
var res = cs.Substring( 4 );
Console.Write(res);
Hi guys, i have here a string for example
Dim str as String
string = "CodeProject"
now i want a function that will cut the "Project" from the string leaving the string value "Code"
Any ideas on how to do this? Thanks
I dont have google :)
解决方案
You can use regular expression replace method. I am giving the sample in c#.
using System.Text.RegularExpressions; String str = "CodeProject" Regex rgx = new Regex("Project"); string result = rgx.Replace(str , " ");
You can use Sustring method,
string cs = "CodeProject"; var res = cs.Substring(4); Console.Write(res);
这篇关于如何切割我不需要的一部分字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文