字符串中的字符串 [英] string from a string

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

问题描述

在我要附加到字符串变量的网站上有一个段落.

看起来像这样:

{
"id":"499156235",
"login_url":"https://www.testing.com/platform/test_account_login.php?user_id=499156235",
电子邮件":"mhuvdfmt_greenesteerin@tfbnw.net",
密码":"1752836968"
}


我想创建两个变量,其中包含电子邮件"和密码"中的值.
因此,使用上面的示例,我将拥有一个带有mhuvdfmt_greenesteerin@tfbnw.net
的变量
和带有1752836968的变量

解决方案

Try,

 字符串 pattern1 = " ;
字符串 pattern2 = " ;
字符串 email = System.Text.RegularExpressions.Regex.Match(input,pattern1).Value;
字符串密码= System.Text.RegularExpressions.Regex.Match(input,pattern2).Value; 


男孩好家伙.还没有人注意到这是JSON.

我继续使用以下解决方案: StackOverflow问题 [ ^ ].

不要使用批准的答案,而应使用页面代码中的16个投票赞成的答案.他用"answer"中的链接库修复了一个错误.


拆分为",然后拆分为:"上的数组的最后两项,以获取用户名和密码.分享您到目前为止尝试过的代码,以便其他人可以提供更好的帮助.


Have a paragraph on a website that I am attaching to a string variable.

Looks something like this:

{
"id": "499156235",
"login_url": "https://www.testing.com/platform/test_account_login.php?user_id=499156235",
"email": "mhuvdfmt_greenesteerin@tfbnw.net",
"password": "1752836968"
}


I want to create two variables that contain the values from Email and Password.
So using the above example i would have a variable with mhuvdfmt_greenesteerin@tfbnw.net

and a variable with 1752836968

Tried using Regex and split but can''t seem to get it to work.

解决方案

Try,

string pattern1 = "(?<=\"email\":\x20\").*?(?=\")";
string pattern2 = "(?<=\"password\":\x20\").*?(?=\")";
string email = System.Text.RegularExpressions.Regex.Match(input, pattern1).Value;
string password = System.Text.RegularExpressions.Regex.Match(input, pattern2).Value;


Boy oh boy. No one has noticed that this is JSON yet.

I continue to use the solution from the: StackOverflow Question[^].

Don''t use the approved answer, but instead use the 16 Up-voted answer with the code in the page. He fixed a bug with the linked library in the "answer".


Split over "," then split last two items in the array over ":" to get the username and password. Share the code you have tried so far so that someone can provide better help.


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

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