从c#中的字符串中提取列表中的所有.jpg文件名字符串
本文关键字:字符串 jpg 文件名 提取 列表 | 更新日期: 2023-09-27 18:17:41
我有以下大字符串,我想要所有的。jpg文件名扩展到字符串列表在c#中,但我不知道如何得到它。
[{'"url'":'"https:''/''/''/data''/menus''/799''/799''/dd2d49c78b1fe3a9cea5761d90132ff1.jpg'",'"href'":'"https:''/''/''/data''/menus''/799''/799''/dd2d49c78b1fe3a9cea5761d90132ff1.jpg'",'"filename'":'"dd2d49c78b1fe3a9cea5761d90132ff1.jpg'",'"url_master'":'"menus_original''/799''/799''/dd2d49c78b1fe3a9cea5761d90132ff1.jpg'",'"path_master'":'"''/home''/foodie''/zomato_data''/menus_original''/799''/799''/dd2d49c78b1fe3a9cea5761d90132ff1.jpg'",'"data_center'":'"'",'"menu_type'":'"FOOD'",'"title'":'"FOOD'",'"menu_type_class'":'"FOOD'",'"real_menu_type'":'"FOOD'",'"is_salt_special_menu'":0,'"start_date'":'"'",'"consumer_upload'":0,'"start_date_formatted'":'"'",'"end_date'":'"'",'"end_date_formatted'":'"'",'"id'":131698200},{'"url'":'"https:''/''/''/data''/menus''/799''/799''/f9f923c43b6b2d2a87ad8ce22b9995da.jpg'",'"href'":'"https:''/''/''/data''/menus''/799''/799''/f9f923c43b6b2d2a87ad8ce22b9995da.jpg'",'"filename'":'"f9f923c43b6b2d2a87ad8ce22b9995da.jpg'",'"url_master'":'"menus_original''/799''/799''/f9f923c43b6b2d2a87ad8ce22b9995da.jpg'",'"path_master'":'"''/home''/foodie''/zomato_data''/menus_original''/799''/799''/f9f923c43b6b2d2a87ad8ce22b9995da.jpg'",'"data_center'":'"'",'"menu_type'":'"FOOD'",'"title'":'"FOOD'",'"menu_type_class'":'"FOOD'",'"real_menu_type'":'"FOOD'",'"is_salt_special_menu'":0,'"start_date'":'"'",'"consumer_upload'":0,'"start_date_formatted'":'"'",'"end_date'":'"'",'"end_date_formatted'":'"'",'"id'":131698203},{'"url'":'"https:''/''/''/data''/menus''/799''/799''/ea3117de65882f14723480841940b5b1.jpg'",'"href'":'"https:''/''/''/data''/menus''/799''/799''/ea3117de65882f14723480841940b5b1.jpg'",'"filename'":'"ea3117de65882f14723480841940b5b1.jpg'",'"url_master'":'"menus_original''/799''/799''/ea3117de65882f14723480841940b5b1.jpg'",'"path_master'":'"''/home''/foodie''/zomato_data''/menus_original''/799''/799''/ea3117de65882f14723480841940b5b1.jpg'",'"data_center'":'"'",'"menu_type'":'"FOOD'",'"title'":'"FOOD'",'"menu_type_class'":'"FOOD'",'"real_menu_type'":'"FOOD'",'"is_salt_special_menu'":0,'"start_date'":'"'",'"consumer_upload'":0,'"start_date_formatted'":'"'",'"end_date'":'"'",'"end_date_formatted'":'"'",'"id'":131698204}]
我想从sting:
dd2d49c78b1fe3a9cea5761d90132ff1.jpg
dd2d49c78b1fe3a9cea5761d90132ff1.jpg
dd2d49c78b1fe3a9cea5761d90132ff1.jpg
f9f923c43b6b2d2a87ad8ce22b9995da.jpg
f9f923c43b6b2d2a87ad8ce22b9995da.jpg
谢谢…提前
如果您只需要。jpg文件名,您可以尝试下面这个简单的正则表达式:
'w+'.jpg
演示:https://regex101.com/r/KMWtZY/1
你可以在c#中这样使用它:
var regex = new Regex(@"'w+'.jpg");
return regex.Matches(strInput);
来源:1
您的字符串似乎是一个JSON字符串。因此,将JSON解解码为对象并获取
等值将是一种更简单方便的方法。为JSON字符串的对象创建一个类
public class YourData
{
public string url { get; set; }
public string href { get; set; }
public string filename { get; set; }
public string url_master { get; set; }
public string path_master { get; set; }
public string data_center { get; set; }
public string menu_type { get; set; }
public string title { get; set; }
public string menu_type_class { get; set; }
public string real_menu_type { get; set; }
public int is_salt_special_menu { get; set; }
public string start_date { get; set; }
public int consumer_upload { get; set; }
public string start_date_formatted { get; set; }
public string end_date { get; set; }
public string end_date_formatted { get; set; }
public int id { get; set; }
}
比//From wherever you are reading it.
string jsonstr = "Your Json String";
//I Removed all the / and ' from the string
jsonstr = jsonstr.Replace("/", "");
jsonstr = jsonstr.Replace("''", "");
//at last of the string you have something like this
//;'n .menuTypes = ['"DEFAULT'",'"FOOD'",'"BAR'",'"DELIVERY'",'"SPECIAL'",'"TAKEAWAY'",'"INTERNAL'"];'n
//which is not the part of the JSON string. So I removed that part as well to make it a valid JSON
jsonstr = jsonstr.Remove(jsonstr.IndexOf(";n"));
//Console.WriteLine(jsonstr); //You can uncomment it to see how JSON looks after cleaning.
//Just Deserialize the JSON
List<YourData> yd = JsonConvert.DeserializeObject<List<YourData>>(jsonstr);
//Loop to get all the filenames or any other fields you want
foreach(YourData ydd in yd)
{
Console.WriteLine(ydd.filename);
}