LotusScript里的字符串处理函数在截取子字符串方面很方便好用。笔者数年前曾经比较三种脚本语言中的这类字符串处理函数,LotusScript的最全面实用。即使在C#这样新且类库设计优良的语言里,字符串类也没有类似的方法。
Vbscript | Javascript | LotusScript | LotusScript里函数的功能 |
Left | slice | Left | 截取字符串最左边的指定长度的子字符串。 |
Right | substr | Right | 截取字符串最右边的指定长度的子字符串。 |
Mid | substring | Mid | 截取字符串指定位置起的指定长度的子字符串。 |
|
| Strleft | 在字符串S1里从左往右查找字符串S2,返回S1中位于S2左边的子字符串。 |
|
| Strleftback | 在字符串S1里从右往左查找字符串S2,返回S1中位于S2左边的子字符串。 |
|
| Strright | 在字符串S1里从左往右查找字符串S2,返回S1中位于S2右边的子字符串。 |
|
| Strrightback | 在字符串S1里从右往左查找字符串S2,返回S1中位于S2右边的子字符串。 |
LotusScript的这些函数使用习惯了,用其他语言的时候就会很想念。于是笔者便在C#里创建了一个StringUtility类,模拟了Strleft、Strleftback、Strright和Strrightback这些函数:
//Mimic LotusScript string functions
public class StringUtility
{
#region Left function
//参数source为源字符串,value为要查找的子字符串,include指示返回的结果是否包含要查找的子字符串。以下几个方法的参数含义类似。
public static string Left(string source,string value,bool include)
{
int pos = source.IndexOf(value);
if (pos > -1)
{
if (include)
{
return source.Substring(0, pos + value.Length);
}
else
{
return source.Substring(0, pos);
}
}
else
{
return "";
}
}
//上面方法的重载,只接受两个字符串参数,返回的结果不包括要查找的子字符串。
public static string Left(string source, string value)
{
return Left(source, value, false);
}
//将第一个Left方法的第二个字符串参数重载为字符类型。
public static string Left(string source, char value,bool include)
{
return Left(source, Convert.ToString(value), include);
}
public static string Left(string source, char value)
{
return Left(source, value, false);
}
#endregion
#region Right() function
public static string Right(string source, string value, bool include)
{
int pos = source.IndexOf(value);
if (pos > -1)
{
if (include)
{
return source.Substring(pos);
}
else
{
return source.Substring(pos + value.Length);
}
}
else
{
return "";
}
}
public static string Right(string source, string value)
{
return Right(source, value, false);
}
public static string Right(string source, char value, bool include)
{
return Right(source, Convert.ToString(value), include);
}
public static string Right(string source, char value)
{
return Right(source, value, false );
}
#endregion
#region LeftBack() function
public static string LeftBack(string source, string value, bool include)
{
int pos = source.LastIndexOf(value);
if (pos > -1)
{
if (include)
{
return source.Substring(0, pos + value.Length);
}
else
{
return source.Substring(0, pos);
}
}
else
{
return "";
}
}
public static string LeftBack(string source, string value)
{
return LeftBack(source, value, false);
}
public static string LeftBack(string source, char value, bool include)
{
return LeftBack(source, Convert.ToString(value), false);
}
public static string LeftBack(string source, char value)
{
return LeftBack(source, value, false );
}
#endregion
#region RightBack() function
public static string RightBack(string source, string value, bool include)
{
int pos = source.LastIndexOf(value);
if (pos > -1)
{
if (include)
{
return source.Substring(pos);
}
else
{
return source.Substring(pos + value.Length);
}
}
else
{
return "";
}
}
public static string RightBack(string source, string value)
{
return RightBack(source, value, false);
}
public static string RightBack(string source, char value, bool include)
{
return RightBack(source, Convert.ToString(value), include);
}
public static string RightBack(string source, char value)
{
return RightBack(source, value, false );
}
#endregion
}
有兴趣的朋友也可以在其他语言里模拟LotusScript的这些函数。
分享到:
相关推荐
分四个部分,都只是与lotusscript相关的。 1,用LotusScript访问修改数据库,包含lotusscript基础 2,用户界面操作 3,创建和修改文档 4,使用On Error敘述追踪 runtime错误
LotusScript基本语法知识,个人收集和总结,希望对大家有帮助.
LotusScript程序开发经验总结.doc
LotusScript中数据库文档操作[定义].pdf
这里以VC为范例: 用VC中的建立Win32DLL库来建立动态连接库,注意增加.DEF文件,在其中的EXPORT中加入接口函数名(全用大写): 一个函数名一行
LotusScript语法入门中文版 PDF格式。
LotusScript程序开发经验总结LotusScript程序开发经验总结LotusScript程序开发经验总结LotusScript程序开发经验总结LotusScript程序开发经验总结LotusScript程序开发经验总结LotusScript程序开发经验总结LotusScript...
domino通过lotusscript解析xml,支持xml文件、流及字符串,可以使用对象的方式访问创建xml,如:xmldocument.标签1.子标签3.getvalue
LotusScript学习资料
lotusscript技巧介绍
LotusScript程序设计,做为一个DOMINO开发人员这个你都没有,怎么行呢。10分值
B/S模式通过LotusScript直接导出txt文件,文件中只有最重要的输出部分,其余需自行补充完成。
LotusScript学习资料,详细介绍了LotusScript的语法,配有丰富的例子;值得一看……
LotusScript语言的使用基本知识与样例, LotusScript语言的使用基本知识与样例, LotusScript语言的使用基本知识与样例
lotusscript适合初学者学习,快来下载吧。
lotusScript(代理)导入Excel
\'在LotusScript中取得当前用户名的几种方法 假设当前用户为\"microsand/edrc/china\" 一、 user=Session.Commonusername 值为\"microsand\" 二、 user=Session.username 值为“CN=microsand/OU=edrc/O=China”
可以根据需要在NOTES的任意对象中附加LotusScript语句和公式。 LotusScript是一个完全面向对象的程序设计语言,具有丰富的类,方法和属性,包含有集成的对象浏览器和程序开发环境。 NOTES公式语言包含一整套的...
LotusScript培训讲义,你还在看不懂domino的help发愁么?下载这个就好了!哈!
非常不错LotusScript入门向导,适合初学者