[转]字符串工具类,保持更新

http://ongsh.iteye.com/blog/860268

package  
{
	/**
	 * ...
	 * @author ongsh
	 */
	public class StringUtil 
	{
		
		/**
		 * 把字符串中的占位符 {0} {1} 用数组中的字符串替换
		 * @param	source	源字符串
		 * @param	args	待替换字符串数组
		 * @return	替换后的字符串
		 */
		public static function replacePlaceholder(source:String, args:Array):String
		{
			var pattern:RegExp = /{(\d)}/g;
			 
			source =  source.replace(pattern, function():String {
				return args[arguments[1]];
			});
			
			return source;
		}
		
		/**
		 * 替换空白字符分割符
		 * @param	source	源字符串
		 * @param	sep		分隔符
		 * @return	结果字符串
		 */
		public static function replaceBlankSep(source:String,sep:String):String
		{
			//剔除前后空格
			source = trim(source);
			
			return source.replace(/\s+/g,sep);;
		}
		
		
		/**
		 * 剔除字符串前后空白
		 * @param	str	源字符串
		 * @return	结果字符串
		 */
		public static function trim(str:String):String
		{
			return str.replace(/(^\s+)|(\s+$)/g,"");   
		}
		
		
		
	}

}

你可能感兴趣的:(apache,Blog)