Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 AS3-字符串拆分网页是';行不通_Actionscript 3 - Fatal编程技术网

Actionscript 3 AS3-字符串拆分网页是';行不通

Actionscript 3 AS3-字符串拆分网页是';行不通,actionscript-3,Actionscript 3,我有一个网页上的一长串HTML。我想进入内容,我在内容之前发现: <span style='margin-left:3px'><g:plusone size='medium' count='false'></g:plusone></span> </div> 有一个换行符,我认为ActionScript3在使用split时不喜欢换行符。例如: var theContent:Array = htmlSource.split("<

我有一个网页上的一长串HTML。我想进入内容,我在内容之前发现:

<span style='margin-left:3px'><g:plusone size='medium' count='false'></g:plusone></span>
</div>

有一个换行符,我认为ActionScript3在使用split时不喜欢换行符。例如:

var theContent:Array = htmlSource.split("<span style='margin-left:3px'><g:plusone size='medium' count='false'></g:plusone></span></div>");
var theContent:Array=htmlSource.split(“”);
输出整个html源代码的一个大数组


我如何才能成功获取内容?我试过了/r,它不起作用

您是否尝试过
\n

var theContent:Array = htmlSource.split("...snip...</span>\n</div>");
var theContent:Array=htmlSource.split(“…snip…\n”);

为什么不做一个简单的find+substr

var sStr:String="<span style='margin-left:3px'><g:plusone size='medium' count='false'></g:plusone></span></div>";
var idx:int=htmlSource.indexOf(sStr);
var len:int=sStr.length;

var content:String=htmlSource.substr(idx+len);
var-sStr:String=”“;
var idx:int=htmlSource.indexOf(sStr);
变量len:int=sStr.length;
变量内容:String=htmlSource.substr(idx+len);

使用正则表达式怎么样

var regExp:RegExp = /(<span style='margin-left:3px'><g:plusone size='medium' count='false'><\/g:plusone><\/span>\s?<\/div>)(.*)/s;
var content:String = htmlSource.replace(regExp, "$2");
var regExp:regExp=/(\s?)(.*)/s;
变量内容:String=htmlSource.replace(regExp,“$2”);
“$2”
返回第二个捕获组(即,在您提供的分隔符之后的所有内容)。如果需要数组,请使用
match(regExp)

\s?
和dotall标志(
s
结尾)完成作业


注意:这是一段非常懒惰的代码,因为您可以轻松地减少regExp。原则是效果。

如果不插入
部分,而字符串以
结尾,会发生什么情况?它可以工作,但内容的开头很难看。我试着对进行另一次拆分,但似乎不起作用,可能是因为不可见的换行符。我相信问题在于换行符。不,换行符没有问题。Split处理换行符和/或回车符的方式与处理任何其他字符一样。这意味着即使
htmlSource
字符串中有换行符,它也会并且确实起作用。但是,它可能失败的一个地方是,如果您正在查找的字符串(
Nope,刚刚尝试过它)不起作用。在删除doctype的前几个字符的情况下,输出几乎整个HTML。