Last active
September 12, 2022 08:50
-
-
Save nonkit/0edeae02b34cd485caf91591491f71b4 to your computer and use it in GitHub Desktop.
Small Basic Pseudo Text Object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Text_Compare | |
' Text | compare texts with case sensitive option | |
' param["text1"], param["text2"] - to compare | |
' param["caseSensitive"] - "True" if case sensitive | |
' return eq = "True" if text1 = text2 | |
' return gt = "True" if text1 > text2 | |
' return lt = "True" if text1 < text2 | |
If param["caseSensitive"] Then | |
text1 = param["text1"] | |
text2 = param["text2"] | |
Else | |
text1 = Text.ConvertToLowerCase(param["text1"]) | |
text2 = Text.ConvertToLowerCase(param["text2"]) | |
EndIf | |
If (text1 + 0 = text1) And (text2 + 0 = text2) Then | |
' both text1 and text2 are numbers | |
eq = "False" | |
gt = "False" | |
lt = "False" | |
If text1 = text2 Then | |
eq = "True" | |
ElseIf text1 > text2 Then | |
gt = "True" | |
ElseIf text1 < text2 Then | |
lt = "True" | |
EndIf | |
Else | |
Text_CompareTexts() | |
EndIf | |
EndSub | |
Sub Text_CompareTexts | |
' Text | compare texts | |
' param text1, text2 - to compare | |
' return eq = "True" if text1 = text2 | |
' return gt = "True" if text1 > text2 | |
' return lt = "True" if text1 < text2 | |
eq = "False" | |
gt = "False" | |
lt = "False" | |
txt1 = Text.ConvertToLowerCase(text1) | |
txt2 = Text.ConvertToLowerCase(text2) | |
len1 = Text.GetLength(txt1) | |
len2 = Text.GetLength(txt2) | |
len = Math.Min(len1, len2) | |
For p = 1 To len | |
c1 = Text.GetCharacterCode(Text.GetSubText(txt1, p, 1)) | |
c2 = Text.GetCharacterCode(Text.GetSubText(txt2, p, 1)) | |
If c1 > c2 Then | |
gt = "True" | |
p = len ' exit For | |
ElseIf c1 < c2 Then | |
lt = "True" | |
p = len ' exit For | |
Else | |
' compare case | |
c1 = Text.GetCharacterCode(Text.GetSubText(text1, p, 1)) | |
c2 = Text.GetCharacterCode(Text.GetSubText(text2, p, 1)) | |
If c1 > c2 Then | |
gt = "True" | |
p = len ' exit For | |
ElseIf c1 < c2 Then | |
lt = "True" | |
p = len ' exit For | |
EndIf | |
EndIf | |
EndFor | |
If gt = "False" And lt = "False" Then | |
If len1 > len2 Then | |
gt = "True" | |
ElseIf len1 < len2 Then | |
lt = "True" | |
Else | |
eq = "True" | |
EndIf | |
EndIf | |
EndSub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Text_IsNumber | |
' Text | check if the text is number | |
' param n - text to check | |
' return match - "True" if match | |
' return value - number | |
If n * 1 = n Then | |
match = "True" | |
value = n * 1 | |
Else | |
match = "False" | |
EndIf | |
EndSub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Text_Sort | |
' Text | sort txt array | |
' param txt[] - text array | |
' return list[] - sorted index list | |
n = Array.GetItemCount(txt) | |
list[0] = 1 ' start | |
list[1] = 0 ' end | |
For j = 2 To n | |
i = 0 | |
text1 = txt[list[i]] | |
text2 = txt[j] | |
Text_CompareTexts() | |
While (list[i] <> 0) And lt | |
i = list[i] | |
text1 = txt[list[i]] | |
Text_CompareTexts() | |
EndWhile | |
' insert j after i | |
list[j] = list[i] | |
list[i] = j | |
EndFor | |
EndSub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Text_Split | |
' Text | split text to array by delimiter | |
' param txt - to split | |
' param delim - delimiter | |
' return arry - splitted | |
len = Text.GetLength(txt) | |
p = 1 | |
n = 0 | |
arry = "" | |
_d = Text.GetIndexOf(Text.GetSubTextToEnd(txt, p), delim) | |
While (0 < _d) And (p <= len) | |
n = n + 1 | |
arry[n] = Text.GetSubText(txt, p, _d - 1) | |
p = p + _d | |
_d = Text.GetIndexOf(Text.GetSubTextToEnd(txt, p), delim) | |
EndWhile | |
n = n + 1 | |
arry[n] = Text.GetSubTextToEnd(txt, p) | |
EndSub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment