c#中的字符串操作 [英] string manupulation in c#

查看:71
本文介绍了c#中的字符串操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




i want to find the DatasetID from the string str.
string str={ DatasetID = 13, DatasetName = Assigned Form Submission };



请帮助我。


please help me.

推荐答案

在字符串中找到DatabaseId。从该locaton获取子字符串直到','字符。

这应该给你id。
Locate DatabaseId in the string. From that locaton take a substring till the ',' character.
That should give you the id.


你可以编写不同的方法来查找数据集ID。这可能对获取ID非常有用。



You can write different methods to find the Dataset ID. This might be very useful to get the ID.

private void FindMethod()
{
   string str="{ DatasetID = 13, DatasetName = Assigned Form Submission }";
   int first = str.IndexOf("=") + "=".Length;
   int last = str.LastIndexOf(",");
   string str2 = str.Substring(first, last - first).Trim();
   System.Console.WriteLine("DataSet ID: '{0}'", str2);
}


快速解决方案:



Rapid solution :

string str="{ DatasetID = 13, DatasetName = Assigned Form Submission }";
            string DatasetId = str.Substring(str.IndexOf('=')+1,str.IndexOf(',')-str.IndexOf('=')-1).Trim();





但是你应该解析所有并从中创建一个对象



But you should parse all and create an object from it


这篇关于c#中的字符串操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆