字符串中的字符串

编程入门 行业动态 更新时间:2024-10-22 08:43:09
本文介绍了字符串中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我要附加到字符串变量的网站上有一个段落. 看起来像这样: { "id":"499156235", "login_url":"www.testing/platform/test_account_login.php?user_id=499156235", 电子邮件":"mhuvdfmt_greenesteerin@tfbnw", 密码":"1752836968" } 我想创建两个变量,其中包含电子邮件"和密码"中的值. 因此,使用上面的示例,我将拥有一个带有mhuvdfmt_greenesteerin@tfbnw 的变量 和带有1752836968的变量 解决方案

Try,

字符串 pattern1 = " (?< = \电子邮件\":\ x20 \).*?(?= \")"; 字符串 pattern2 = " (?< = \"密码\:\ x20 \").*?(?= \)" ; 字符串 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": "www.testing/platform/test_account_login.php?user_id=499156235", "email": "mhuvdfmt_greenesteerin@tfbnw", "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 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.

更多推荐

字符串中的字符串

本文发布于:2023-07-31 08:39:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1257248.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!