如何在C#中解析示例字符串 [英] How to Parse an example string in C#

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

问题描述

我有这个字符串

[
    {
        "url_short":"http:\/\/sample.com\/8jyKHv",
        "url_long":"http:\/\/www.sample.com\/",
        "type":0
    }
]

我想要得到的是http:\/\/sample.com\/8jyKHv并将其翻译为

What I want is to get http:\/\/sample.com\/8jyKHv and translate it to

http://sample.com/8jyKHv

有可能吗?

推荐答案

确实推荐使用JSON方法,但是不能提供太多有关它的信息.这是使用正则表达式的另一种方法:

The JSON way is for sure recommended, but cant tell much about it. Here's the alternative way with regex:

Regex rgxUrl = new Regex("\"url_short\":\"(.*?)\",\"");
Match mUrl = rgxUrl.Match(yourString);

string url = Regex.Replace(mUrl.Groups[1].Value, @"\", "");

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

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