You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
using System.Text.RegularExpressions ;
using RoBot.Core.ConstValue ;
using RoBot.Core.Helper ;
using RoBot.Goods.Dto ;
namespace RoBot.Goods.Service
{
public class GoodsService
{
private static Regex Regex = new Regex ( @"价格[:: ](\d+万)\s+([^\s]+)" ) ;
/// <summary>
/// 解析物品信息
/// </summary>
/// <param name="text"></param>
public static void AnalysisGoodsText ( string text )
{
if ( string . IsNullOrWhiteSpace ( text ) ) return ;
List < GoodsInfo > results = new ( ) ;
MatchCollection matches = Regex . Matches ( text ) ;
foreach ( Match match in matches )
{
string price = match . Groups [ 1 ] . Value ;
string name = match . Groups [ 2 ] . Value . Replace ( "\u200b" , "" ) . Replace ( "\u200c" , "" ) . Replace ( "\u200d" , "" ) ; // 去除零宽字符
results . Add ( new ( )
{
Name = name ,
Price = Convert . ToDecimal ( price . Replace ( "万" , "" ) ) ,
LastUpdateTime = DateTime . Now
} ) ;
}
foreach ( GoodsInfo item in results )
{
RedisHelper . Client . HSet ( RedisPrefix . GoodsKey , item . Name , item ) ;
}
}
}
}