一些 lotus script 函数

本文介绍了一种使用LotusScript进行字符串处理的方法,包括字符串替换、分割及从INI文件读取特定值的功能实现。通过具体示例展示了如何在LotusScript中操作字符串和INI文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Function Replace(fstr As String,rstr As String,tstr As String) As String
        //r5适用
 '''''''''''''''''''''''
 'fstr 要处理的字符串
 'rstr 要替换的字符串
 'tstr 字符串替换目标
 ''''''''''''''''''''''''
 While Instr(fstr,rstr)>0
  strtemp=Strleft(fstr,rstr)+tstr+Strright(fstr,rstr)
  fstr=strtemp
 Wend
 Replace=fstr
End Function

Function Split(strSoucer As String,sp As String) As Variant
  //r5适用
 Dim y() As String
 Dim strtemp As String,i As Integer
 i=0
 While Instr(strSoucer,sp)>0 And strSoucer<>""
  Redim Preserve y(i)
  strtemp=Strleft(strSoucer,sp)
  y(i)=strtemp
  strSoucer=Strright(strSoucer,sp)
  i=i+1
 Wend
 Redim Preserve y(i)
 y(i)=strSoucer
 Split=y
End Function
Sub getV()
'lotus script 文件操作
 Dim fileNum As Integer
 Dim fileName As String
 fileNum% = Freefile()
 fileName$ = "D:/nluserenpass.ini"
 Open fileName$ For Random As fileNum%
 Dim rec As String
 
 Seek fileNum%, 1
 Do While Not Eof(fileNum%)
  Get #fileNum%, , rec
  Print rec
 Loop
 Close fileNum%
End Sub
Function GetIniValue(section As String,key As String,filepath As String) As String
 ''''''''''''''''''''''''''''

'ini 文件操作,引用此函数注意代理权限最低为2
 '获取ini文件中某一项值
 ''''''''''''''''''''''''''''
 On Error Goto errorH
 Dim session As New NotesSession
 Dim stream As NotesStream
 Set stream=session.CreateStream
 Dim flag_isin_sec As Boolean,flag_geted As Boolean
 Dim rtstr As String
 flag_isin_sec=False
 flag_geted=False
 section="["+section+"]"
 If Not stream.Open(filepath, "GB2312") Then
  Messagebox filepath,, "Open failed"
  Exit Function
 End If
 key=key+"="
 While Not stream.IsEOS And Not flag_geted
  buffer$ = Trim(stream.ReadText(STMREAD_LINE,EOL_PLATFORM))
  buffer$=Replace(Replace(Trim(buffer$),Chr(13),""),Chr(10),"")
  If flag_isin_sec Then
   '首先查找 section 直到下个section出现
   If Left(buffer$,1)="[" And Right(buffer$,1)="]" Then
    flag_isin_sec=False
   End If
  End If
  If buffer$=section Then
   flag_isin_sec=True
  End If
  If flag_isin_sec Then
   If Instr(buffer$,key)>0 Then
    rtstr=Strright(buffer$,"=")
    flag_geted=True
   End If
  End If
 Wend
 stream.Close
 GetIniValue=Replace(Replace(Trim(rtstr),Chr(13),""),Chr(10),"")
 Exit Function
errorH:
 Dim sError As New NotesSession
 Dim dbError As NotesDatabase
 Dim agError As NotesAgent
 Set agError=sError.CurrentAgent
 Set dbError=sError.CurrentDatabase
 Msgbox dbError.title+"("+dbError.FilePath+")::"+agError.Name+_
 "->LSINI->GetIniValue->Error="+Error+":Erl="+Cstr(Erl)
 Exit Function
End Function

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值