How to resolve the algorithm String matching step by step in the VBScript programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm String matching step by step in the VBScript programming language
Table of Contents
Problem Statement
Given two strings, demonstrate the following three types of string matching:
Optional requirements:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm String matching step by step in the VBScript programming language
Source code in the vbscript programming language
Function StartsWith(s1,s2)
StartsWith = False
If Left(s1,Len(s2)) = s2 Then
StartsWith = True
End If
End Function
Function Contains(s1,s2)
Contains = False
If InStr(1,s1,s2) Then
Contains = True & " at positions "
j = 1
Do Until InStr(j,s1,s2) = False
Contains = Contains & InStr(j,s1,s2) & ", "
If j = 1 Then
If Len(s2) = 1 Then
j = j + InStr(j,s1,s2)
Else
j = j + (InStr(j,s1,s2) + (Len(s2) - 1))
End If
Else
If Len(s2) = 1 Then
j = j + ((InStr(j,s1,s2) - j) + 1)
Else
j = j + ((InStr(j,s1,s2) - j) + (Len(s2) - 1))
End If
End If
Loop
End If
End Function
Function EndsWith(s1,s2)
EndsWith = False
If Right(s1,Len(s2)) = s2 Then
EndsWith = True
End If
End Function
WScript.StdOut.Write "Starts with test, 'foo' in 'foobar': " & StartsWith("foobar","foo")
WScript.StdOut.WriteLine
WScript.StdOut.Write "Contains test, 'o' in 'fooooobar': " & Contains("fooooobar","o")
WScript.StdOut.WriteLine
WScript.StdOut.Write "Ends with test, 'bar' in 'foobar': " & EndsWith("foobar","bar")
You may also check:How to resolve the algorithm Terminal control/Hiding the cursor step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Read a file character by character/UTF8 step by step in the Sidef programming language
You may also check:How to resolve the algorithm Yahoo! search interface step by step in the ARM Assembly programming language
You may also check:How to resolve the algorithm File extension is in extensions list step by step in the 11l programming language
You may also check:How to resolve the algorithm Program name step by step in the D programming language