ActionScript 3 Twitter推文字符串编码实体实用程序
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 Twitter推文字符串编码实体实用程序相关的知识,希望对你有一定的参考价值。
package {
/**
* @author Ninjaparade
*/
public class TwitterStringUtil
{
public static function encodeTwitterString(tweet : String) : String
{
var twitterHash : RegExp = /(\#[a-zA-Z0-9_%]*)/g;
var twitterUser : RegExp = /(\@[a-zA-Z0-9_%]+)/ig;
var twitterLink : RegExp = /(https?:\/\/)?(www\.)?([a-zA-Z0-9_%]*)\b\.[a-z]{2,4}(\.[a-z]{2})?((\/[a-zA-Z0-9_%]*)+)?(\.[a-z]*)?/g;
var str : String = tweet;
var arr : Object = str.match(twitterLink);
if (arr != null)
{
for each ( var s:String in arr ) {
str = str.replace(s, encodeURL(s));
}
}
arr = str.match(twitterHash);
if (arr != null)
{
for each (var k : String in arr) {
str = str.replace(k, replaceHashtoURL(k));
}
}
arr = str.match(twitterUser);
if (arr != null)
{
for each (var j : String in arr) {
str = str.replace(j, replaceURL(j));
// str = "<a href = \"http://www.twitter.com/" + j.substr(1, j.length) + "\" " + "target=\"_blank\">" + j + "</a>";
}
}
return str;
}
public static function searchTwitterHash(value : String) : String
{
var pattern : RegExp = /(\#[a-zA-Z0-9_%]*)/g;
var str : String = value;
var arr : Object = value.match(pattern);
// if(arr != null) {
for each ( var s:String in arr ) {
str = str.replace(s, replaceHashtoURL(s));
// }
}
return str;
}
public static function searchTwitterUser(value : String) : String
{
var pattern : RegExp = /(\@[a-zA-Z0-9_%]+)/ig;
var str : String = value;
var arr : Object = value.match(pattern);
for each ( var s:String in arr ) {
str = str.replace(s, replaceURL(s));
}
return str;
}
public static function searchTwitterURL(value : String) : String
{
var pattern : RegExp = /(https?:\/\/)?(www\.)?([a-zA-Z0-9_%]*)\b\.[a-z]{2,4}(\.[a-z]{2})?((\/[a-zA-Z0-9_%]*)+)?(\.[a-z]*)?/g;
var str : String = value;
var arr : Object = value.match(pattern);
if (arr != null)
{
for each ( var s:String in arr ) {
str = str.replace(s, encodeURL(s));
}
}
return str;
}
public static function replaceURL(value : String) : String
{
var str : String = "<a href = \"http://www.twitter.com/" + value.substr(1, value.length) + "\" " + "target=\"_blank\">" + value + "</a>";
return str;
}
public static function replaceHashtoURL(value : String) : String
{
var str : String = "<a href = \"http://twitter.com/#search?q=%23" + value.substr(1, value.length) + "\" " + "target=\"_blank\">" + value + "</a>";
return str;
}
public static function encodeURL(value : String) : String
{
var str : String = "<a href = " + "\"" + value + "\" " + "target=\"_blank\">" + value + "</a>";
return str;
}
}
}
以上是关于ActionScript 3 Twitter推文字符串编码实体实用程序的主要内容,如果未能解决你的问题,请参考以下文章
ActionScript 3 Twitter推文字符串编码实体实用程序
ActionScript 3 使用Twitter API的PlayBook OAuth示例
ActionScript 3 在Twitter上分享(Bit.ly缩短链接)[FLEX]
ActionScript 3 AS3:使用SWX访问Twitter用户的公共时间线
从我的网站向 Twitter 帐户发布推文时如何使文本变为粗体或斜体
ActionScript 3 文字填充和边距