×

replaceall is not a function

正则表达式“或“的使用?VB与Word的集成问题

admin admin 发表于2022-07-17 18:23:08 浏览99 评论0

抢沙发发表评论

扩展信息正则表达的作用:1.匹配检查字符串是否符合正则表达式中的规则,许多编程语言支持将正则表达式用于字符串操作,所有数字块都会更靠近滑动方向,字符串str =“ abc”;String reg=“\\d?“;//次表达式表示字符串的第一位只能是字母,例如:字符串str =“ SFHJHFH136HJASDF73466247FSJHA8437482JFJSFH746376”str.replaceAll(“\\d{3,}“,“#“);//表示将连续出现三个或三个以上的数字替换成“#”,当玩家拼图出现数字时,系统给出的数字块不是2或4,正则表达式通常用于检索和替换那些符合特定模式的文本(规则)。

正则表达式“或“的使用

正则表达式,也称为规则表达式。它是计算机科学的概念。

正则表达式通常用于检索和替换那些符合特定模式的文本(规则)。许多编程语言支持将正则表达式用于字符串操作。例如,perl内置强大的正则表达式引擎。正常的概念表达最初是由UNIX中的工具软件(例如SED和GREP)推广的。

正则表达式通常被缩写为“正则”,单打是Regexp,Regex和Clurals是Regexps,Regexes和Regexen。

扩展信息

正则表达的作用:

1.匹配

检查字符串是否符合正则表达式中的规则。一旦与不匹配,它将返回false。

字符串str =“ abc”;

String reg=“\\d?“;//次表达式表示字符串的第一位只能是字母,第二位只能是数字或没有boolean flag=str.matches(reg);//返回结果为true。

2.切割

SO称为的切割是根据某个规则将字符串分为多个子弦,例如:

字符串str =“张圣,历史,王吴”。

字符串reg =“,”;//表示逗号作为切割符号。

字符串arr = str.split(reg);//返回结果为{“ Zhangsan”,“ Lisi”,“ Wangwu}。

3.更换

即将遵守字符串规则的字符被指定的字符替换,例如:

字符串str =“ SFHJHFH136HJASDF73466247FSJHA8437482JFJSFH746376”

str.replaceAll(“\\d{3,}“,“#“);//表示将连续出现三个或三个以上的数字替换成“#”。

参考信息来源:百度百科全书常规表达公式

VB与Word的集成问题


Private mywdapp As Word.Application
Private mysel As Object
’属性值的模块变量
Private C_TemplateDoc As String
Private C_newDoc As String
Private C_PicFile As String
Private C_ErrMsg As Integer
Public Event HaveError()
’***************************************************************
’ErrMsg代码:1-word没有安装 2 - 缺少参数 3 - 没权限写文件
’ 4 - 文件不存在

’***************************************************************
Public Function PrtDoc()
mywdapp.Dialogs(wdDialogFilePrint).Show
mywdapp.Visible = False
End Function
Public Function ReplacePic(FindStr As String, Optional Time As Integer = 0) As Integer
’********************************************************************************
’ 从Word.Range对象mysel中查找所有FindStr,并替换为PicFile图像
’ 替换次数由time参数确定,为0时,替换所有
’********************************************************************************
If Len(C_PicFile) = 0 Then
C_ErrMsg = 2
Exit Function
End If
Dim i As Integer
Dim findtxt As Boolean
mysel.Find.ClearFormatting
mysel.Find.Replacement.ClearFormatting
With mysel.Find
.Text = FindStr
.Replacement.Text = ““
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
mysel.HomeKey Unit:=wdStory
findtxt = mysel.Find.Execute(Replace:=True)
If Not findtxt Then
ReplacePic = 0
Exit Function
End If
i = 1
Do While findtxt
mysel.InlineShapes.AddPicture FileName:=C_PicFile
If i = Time Then Exit Do
i = i + 1
mysel.HomeKey Unit:=wdStory
findtxt = mysel.Find.Execute(Replace:=True)
Loop
ReplacePic = i
End Function
Public Function FindThis(FindStr As String) As Boolean
If Len(FindStr) = 0 Then
C_ErrMsg = 2
Exit Function
End If
mysel.Find.ClearFormatting
mysel.Find.Replacement.ClearFormatting
With mysel.Find
.Text = FindStr
.Replacement.Text = ““
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
mysel.HomeKey Unit:=wdStory
FindThis = mysel.Find.Execute
End Function
Public Function ReplaceChar(FindStr As String, RepStr As String) As Integer
’********************************************************************************
’ 从Word.Range对象mysel中查找FindStr,并替换为RepStr
’ 替换次数由time参数确定,为0时,替换所有
’********************************************************************************
Dim findtxt As Boolean
If Len(FindStr) = 0 Then
C_ErrMsg = 2
RaiseEvent HaveError
Exit Function
End If
mysel.Find.ClearFormatting
mysel.Find.Replacement.ClearFormatting
With mysel.Find
’MsgBox “1111“
.Text = FindStr
.Replacement.Text = RepStr
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
’ Selection.Find.ClearFormatting
’ Selection.Find.Replacement.ClearFormatting
’ With Selection.Find
’ .Text = “ht_bgrq“
’ .Replacement.Text = “HT_BGRQ“
’ .Forward = True
’ .Wrap = wdFindContinue
’ .Format = False
’ .MatchCase = True
’ .MatchWholeWord = False
’ .MatchByte = True
’ .MatchWildcards = False
’ .MatchSoundsLike = False
’ .MatchAllWordForms = False
’ End With
End With
’mysel.Find.Text = FindStr
’mysel.Find.Replacement.Text = RepStr
’If Time 》 0 Then
’ For i = 1 To Time
’ mysel.HomeKey Unit:=wdStory
’ findtxt = mysel.Find.Execute(Replace:=wdReplaceOne)
’ If Not findtxt Then Exit For
’ Next i
’ If i = 1 And Not findtxt Then
’ ReplaceChar = 0
’ Else
’ ReplaceChar = i
’ End If
’Else
mysel.Find.Execute Replace:=wdReplaceAll
’End If
End Function
Public Sub DelRow()
’删除表格的当前行
mysel.Rows.Delete
End Sub
Public Function GetPic(PicData() As Byte, FileName As String) As Boolean
’********************************************************************************
’ 把图像数据PicData,存为PicFile指定的文件
’********************************************************************************
On Error Resume Next
’If Len(FileName) = 0 Then
’C_ErrMsg = 2
’RaiseEvent HaveError
’Exit Function
’End If
Open FileName For Binary As #1
If Err.Number 《》 0 Then
C_ErrMsg = 3
Exit Function
End If
’二进制文件用Get,Put存放,读取数据
Put #1, , PicData
Close #1
C_PicFile = FileName
GetPic = True
End Function
Public Sub TypeTxt(Nr As String)
’在word中输入指定的内容
’ mysel.ParagraphFormat.LeftIndent = CentimetersToPoints(-1.27)
’ mysel.ParagraphFormat.LeftIndent = CentimetersToPoints(-1.27)
mysel.TypeText Nr
mysel.TypeParagraph
End Sub
Public Sub istTbl(Row As Integer, Col As Integer)
’在文档里插入表格
mywdapp.ActiveDocument.Tables.Add Range:=mysel.Range, NumRows:=Row, NumColumns:=Col, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitContent
With mysel.Tables(1)
If .Style 《》 “网格型“ Then
.Style = “网格型“
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
mysel.MoveRight Unit:=wdCharacter, Count:=Col, Extend:=wdExtend
mysel.MoveDown Unit:=wdLine, Count:=Row, Extend:=wdExtend
mysel.ParagraphFormat.Alignment = wdAlignParagraphCenter
mysel.Cells.VerticalAlignment = wdCellAlignVerticalCenter
End Sub
Public Sub DeleteToEnd()
mysel.EndKey Unit:=wdStory, Extend:=wdExtend
mysel.Delete Unit:=wdCharacter, Count:=1
End Sub
Public Sub MoveEnd()
’光标移动到文档结尾
mysel.EndKey Unit:=wdStory
mysel.ParagraphFormat.Alignment = wdAlignParagraphJustify
End Sub
Public Sub GotoLine(LineTime As Integer)
mysel.GoTo What:=wdGoToLine, Which:=wdGoToFirst, Count:=LineTime, Name:=““
End Sub
Public Sub OpenDoc(view As Boolean)
On Error Resume Next
’********************************************************************************
’ 打开Word文件,并给全局变量mysel赋值
’********************************************************************************
If Len(C_TemplateDoc) 》 0 Then
Shell “cmd /c del “ & C_TemplateDoc, “0“
mywdapp.Documents.Add
’mywdapp.ActiveDocument.SaveAs C_TemplateDoc
’mywdapp.Documents.Open C_TemplateDoc
If Err.Number 《》 0 Then
C_ErrMsg = 4
RaiseEvent HaveError
’Exit Sub
End If
mywdapp.Visible = view
mywdapp.Activate
Set mysel = mywdapp.Selection
’mysel.Select
End If
End Sub
Public Sub OpenWord()
On Error Resume Next
’********************************************************************************
’ 打开Word程序,并给全局变量mywdapp赋值
’********************************************************************************
Set mywdapp = CreateObject(“word.application“)
If Err.Number 《》 0 Then
C_ErrMsg = 1
RaiseEvent HaveError
Exit Sub
End If
End Sub
Public Sub ViewDoc()
mywdapp.Visible = True
End Sub
Public Sub AddNewPage()
mysel.InsertBreak Type:=wdPageBreak
End Sub
Public Sub WordCut()
’保存模板页面内容
mysel.WholeStory
mysel.Cut
mysel.HomeKey Unit:=wdStory
End Sub
Public Sub WordCopy()
mysel.WholeStory
mysel.Copy
mysel.HomeKey Unit:=wdStory
End Sub
Public Sub WordDel()
mysel.WholeStory
mysel.Delete
mysel.HomeKey Unit:=wdStory
End Sub
Public Sub WordPaste()
’插入模块内容
mysel.Paste
End Sub
Public Sub CloseDoc()
’********************************************************************************
’ 关闭Word文件模本
’********************************************************************************
On Error Resume Next
mywdapp.ActiveDocument.Close False
If Err.Number 《》 0 Then
C_ErrMsg = 3
Exit Sub
End If
End Sub
Public Sub QuitWord()
’********************************************************************************
’ 关闭Word程序
’********************************************************************************
On Error Resume Next
mywdapp.Quit
If Err.Number 《》 0 Then
C_ErrMsg = 3
Exit Sub
End If
End Sub
Public Sub SavetoDoc()
On Error Resume Next
’并另存为文件FileName
mywdapp.ActiveDocument.SaveAs (C_TemplateDoc)
If Err.Number 《》 0 Then
C_ErrMsg = 3
RaiseEvent HaveError
Exit Sub
End If
End Sub
Public Property Get TemplateDoc() As String
TemplateDoc = C_TemplateDoc
End Property
Public Property Let TemplateDoc(ByVal vNewValue As String)
C_TemplateDoc = vNewValue
End Property
Public Property Get DocPage() As Integer
’mysel.Find.ClearFormatting
’mysel.Find.Text = “5927107“
DocPage = mysel.Information(wdNumberOfPagesInDocument)
End Property
Public Property Get newdoc() As String
newdoc = C_newDoc
End Property
Public Property Let newdoc(ByVal vNewValue As String)
C_newDoc = vNewValue
End Property
Public Property Get PicFile() As String
PicFile = C_PicFile
End Property
Public Property Let PicFile(ByVal vNewValue As String)
C_PicFile = vNewValue
End Property
Public Property Get ErrMsg() As Integer
ErrMsg = C_ErrMsg
End Property
***************************************************************
把以上内容保存为VB类模块,通过调用该类就可以实现用VB打开word的操作
-replaceall is not a function

我写2048网页版的游戏用jQuery为什么会出现Uncaught TypeError: string.replace is not a function的错误

String.Replace不是函数翻译:String.Replace不是函数。建议您使用Chrome Developer工具来定位错误的代码行,然后找到问题。

《2048Numberpuzzlegame》是一款数字益智游戏,而《2048》的初始数字则是由2+2组成的基数4。在操作方面的不同则表现为一步一格的移动,变成更为爽快的一次到底。相同数字的方况在靠拢、相撞时会相加。系统给予的数字方块不是2就是4,玩家要想办法在这小小的16格范围中凑出「2048」这个数字方块。-replaceall is not a function

游戏规则非常简单。每次您都可以向上,向下,向左和向右选择一个方向以滑动。每次滑动时,所有数字块都会更靠近滑动方向。将添加和碰撞添加。系统给出的数字块不是2或4。玩家必须找到一种方法,使“ 2048”数字块在这个小16平方英尺的范围内。游戏的图片非常简单。一旦打开整体格,大多数都是灰色的。当玩家拼图出现数字时,颜色将更改。整体样式非常简单。游戏规则也很简单。一开始,2或4个小数(例如2或4个小数)将出现在正方形中。玩家只需要移动一个方向之一即可向上,向下,左右移动。滑动空白块将随机出现一个数字。当碰撞时,相同的数字将被叠加并靠近,然后,即使成功,连续重叠最终将数字汇总在一起。如果您是数字爱好者或才华横溢的数学天才,即使它不是数学天才,普通玩家也可以玩这个游戏。如果您有兴趣,请下载并体验它。-replaceall is not a function