我使用Visual Web Ripper来提取网站上产品的名称和价格。C#:从字符串中提取数字,然后将逗号(,)更改为点(。)
,当我从一个表中提取价格谈到在这样的形式:
氪。 129,30
我需要提取129,30,然后将逗号转为点(129.30)。
Visual Web Ripper可以使用脚本来修改提取的内容。它可以使用标准的正则表达式,C#和VB.NET。
在正则表达式选项卡中我发现,
(\d+.)?(\d+)(.\d+)?
给我129,30,但我不能改变逗号成一个点。
为此,我必须使用C#。它配备了该标准的脚本:
using System;
using VisualWebRipper.Internal.SimpleHtmlParser;
using VisualWebRipper;
public class Script
{
//See help for a definition of WrContentTransformationArguments.
public static string TransformContent(WrContentTransformationArguments args)
{
try
{
//Place your transformation code here.
//This example just returns the input data
return args.Content;
}
catch(Exception exp)
{
//Place error handling here
args.WriteDebug("Custom script error: " + exp.Message);
return "Custom script error";
}
}
}
如何修改它以提取号码,然后以点代替逗号?
谢谢! :)使用'return number.ToString();'我得到“129,30”。现在我怎么得到“129.30”? :) – galskab
它不明显*瑞典克朗,是吗?为什么不是挪威或丹麦文化? – phoog
@galskab'number.ToString(CultureInfo.InvariantCulture)''但真的答案取决于*为什么*你想得到一个带点小数点分隔符的字符串。 – phoog