ScriptForge.String service

The String service provides a collection of methods for string processing. These methods can be used to:

Definitions

Line breaks

The String service recognizes the following line breaks:

Symbolic name

ASCII number

Line feed
Vertical tab
Carriage return
Line feed + Carriage return
File separator
Group separator
Record separator
Next line
Line separator
Paragraph separator

10
12
13
10 + 13
28
29
30
133
8232
8233


Whitespaces

The String service recognizes the following whitespaces:

Symbolic name

ASCII number

Space
Horizontal tab
Line feed
Vertical tab
Form feed
Carriage return
Next line
No-break space
Line separator
Paragraph separator

32
9
10
11
12
13
133
160
8232
8233


Escape sequences

Below is a list of escape sequences that can be used in strings.

Escape Sequence

Symbolic name

ASCII number

\n
\r
\t

Line feed
Carriage return
Horizontal tab

10
13
9


tip

To have the escape sequence "\n" interpreted as an actual string, simply use "\\n" instead of "\" & Chr(10).


Non-printable characters:

Characters defined in the Unicode Character Database as “Other” or “Separator” are considered as non-printable characters.

Control characters (ascii code <= 0x1F) are also considered as non-printable.

Quotes inside strings:

To add quotes in strings use \' (single quote) or \" (double quote). For example:

Service invocation

Before using the ScriptForge.String service the ScriptForge library needs to be loaded using:


      GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
  

The following code snippets show the three ways to call methods in the String service (the ExpandTabs method is used as an example):


        SF_String.ExpandTabs(...)
    

        Dim s : s = SF_String
        s.ExpandTabs(...)
    

        Dim s : s = CreateScriptService("String")
        s.ExpandTabs(...)
    

Properties

The SF_String object provides the following properties:

Name

Skriveverna

Beskriving

sfCR

Yes

Carriage return: Chr(13)

sfCRLF

Yes

Carriage return + Linefeed: Chr(13) & Chr(10)

sfLF

Yes

Linefeed: Chr(10)

sfNEWLINE

Yes

Carriage return + Linefeed, which can be
1) Chr(13) & Chr(10) or
2) Linefeed: Chr(10)
depending on the operating system.

sfTAB

Yes

Horizontal tabulation: Chr(9)


tip

You can use the properties above to identify or insert the corresponding characters inside strings. For example, the Linefeed can be replaced by SF_String.sfLF.


List of Methods in the String Service

Capitalize
Count
EndsWith
Escape
ExpandTabs
FilterNotPrintable
FindRegex
HashStr
HtmlEncode
IsADate
IsAlpha
IsAlphaNum
IsAscii
IsDigit
IsEmail

IsFileName
IsHexDigit
IsIBAN
IsIPv4
IsLike
IsLower
IsPrintable
IsRegex
IsSheetName
IsTitle
IsUpper
IsUrl
IsWhitespace
JustifyCenter
JustifyLeft

JustifyRight
Quote
ReplaceChar
ReplaceRegex
ReplaceStr
Represent
Reverse
SplitLines
SplitNotQuoted
StartsWith
TrimExt
Unescape
Unquote
Wrap


note

The first argument of most methods is the string to be considered. It is always passed by reference and left unchanged. Methods such as Capitalize, Escape, etc return a new string after their execution.


Capitalize

Capitalizes the first character from each word in the input string.

Syntaks:


       SF_String.Capitalize(InputStr As String) As String
     

Parametrar:

InputStr: The string to be capitalized.

Eksempel:


       Dim sName as String : sName = "john smith"
       Dim sCapitalizedName as String
       sCapitalizedName = SF_String.Capitalize(sName)
       MsgBox sCapitalizedName 'John Smith
     

Count

Counts the number of occurrences of a substring or a regular expression within a string.

Syntaks:


        SF_String.Count(InputStr As String, Substring As String[, IsRegex As Boolean][, CaseSensitive As Boolean]) As Long
      

Parametrar:

InputStr: The input string to be examined

Substring: The substring or the regular expression to be used during search

IsRegex: Use True if the substring is a regular expression (default = False)

CaseSensitive: Default = False

Eksempel:


        'Counts the occurrences of the substring "or" inside the input string (returns 2)
        MsgBox SF_String.Count("Lorem ipsum dolor sit amet, consectetur adipiscing elit.", "or", CaseSensitive := False)
        'Counts the number of words with only lowercase letters (returns 7)
        MsgBox SF_String.Count("Lorem ipsum dolor sit amet, consectetur adipiscing elit.", "\b[a-z]+\b", IsRegex := True, CaseSensitive := True)
      
tip

To learn more about regular expressions, refer to the Python's documentation on Regular Expression Operations.


EndsWith

Returns True if a string ends with a specified substring.

The function returns False when either the string or the substring have a length = 0 or when the substring is longer than the string.

Syntaks:


       SF_String.EndsWith(InputStr As String, Substring As String[, CaseSensitive As Boolean]) As Boolean
     

Parametrar:

InputStr: The string to be tested.

Substring: The substring to be searched at the end of InputStr.

CaseSensitive: The comparison can be case sensitive or not (default = False).

Eksempel:


        'Returns True because the method was called with the default CaseSensitive = False
        MsgBox SF_String.EndsWith("abcdefg", "EFG")
        'Returns False due to the CaseSensitive parameter
        MsgBox SF_String.EndsWith("abcdefg", "EFG", CaseSensitive := True)
      

Escape

Converts linebreaks and tabs contained in the input string to their equivalent escaped sequence (\\, \n, \r, \t).

Syntaks:


          SF_String.Escape(InputStr As String) As String
      

Parametrar:

InputStr: The string to be converted.

Eksempel:


          'Returns the string "abc\n\tdef\\n"
          MsgBox SF_String.Escape("abc" & Chr(10) & Chr(9) & "def\n")
        

ExpandTabs

Replaces Tab characters Chr(9) by space characters to replicate the behavior of tab stops.

If a line break is found, a new line is started and the character counter is reset.

Syntaks:


        SF_String.ExpandTabs(InputStr As String[, TabSize As Integer]) As String
      

Parametrar:

InputStr: The string to be expanded

TabSize: This parameter is used to determine the Tab stops using the formula: TabSize + 1, 2 * TabSize + 1 , ... N * TabSize + 1 (default = 8)

Eksempel:


        Dim myText as String
        myText = "100" & SF_String.sfTAB & "200" & SF_String.sfTAB & "300" & SF_String.sfNEWLINE & _
                 "X"  & SF_String.sfTAB & "Y" & SF_String.sfTAB & "Z"
        MsgBox SF_String.ExpandTabs(myText)
        '100     200     300
        'X       Y       Z
      

FilterNotPrintable

Replaces all non-printable characters in the input string by a given character.

Syntaks:


        SF_String.FilterNotPrintable(InputStr As String[, ReplacedBy As String]) As String
      

Parametrar:

InputStr: The string to be searched

ReplacedBy: Zero, one or more characters that will replace all non-printable characters in InputStr (Default = "")

Eksempel:


        Dim LF : LF = Chr(10)
        Dim myText as String
        myText = "Ă Ă©n ÎŁlP”" & LF & " РуссĐșĐžĐč" & "\n"
        MsgBox SF_String.FilterNotPrintable(myText)
        ' "Ă Ă©n ÎŁlP” РуссĐșĐžĐč\n"
      

FindRegex

Finds in a string a substring matching a given regular expression.

Syntaks:


        SF_String.FindRegex(InputStr As String, Regex As String[, Start As Long[, CaseSensitive As Boolean[, Forward As Boolean]]]) As String
      

Parametrar:

InputStr: The string to be searched

Regex: The regular expression

Start: The position in the string where the search will begin. This parameter is passed by reference, so after execution the value of Start will point to the first character of the found substring. If no matching substring is found, Start will be set to 0.

CaseSensitive: Default = False

Forward: Determines the direction of the search. If True, search moves forward. If False search moves backwards (Default = True)

At the first iteration, if Forward = True, then Start should be equal to 1, whereas if Forward = False then Start should be equal to Len(InputStr)

Eksempel:


        Dim lStart As Long : lStart = 1
        Dim result as String
        result = SF_String.FindRegex("abCcdefghHij", "C.*H", lStart, CaseSensitive := True)
        MsgBox lStart & ": " & result
        '3: CcdefghH
      
tip

In the example above, the new value of lStart can be used to keep searching the same input string by setting the Start parameter to lStart + Len(result) at the next iteration.


HashStr

Hash functions are used inside some cryptographic algorithms, in digital signatures, message authentication codes, manipulation detection, fingerprints, checksums (message integrity check), hash tables, password storage and much more.

The HashStr method returns the result of a hash function applied on a given string and using a specified algorithm, as a string of lowercase hexadecimal digits.

The hash algorithms supported are: MD5, SHA1, SHA224, SHA256, SHA384 and SHA512.

Syntaks:


          SF_String.HashStr(InputStr As String, Algorithm As String) As String
      

Parametrar:

InputStr : The string to hash. It is presumed to be encoded in UTF-8. The hashing algorithm will consider the string as a stream of bytes.

Algorithm : One of the supported algorithms listed above, passed as a string.

Eksempel:


          MsgBox SF_String.HashStr("Ć“âˆ‘ÂĄâ„ąÂŁÂąâˆžÂ§Â¶â€ąÂȘÂșâ€“â‰ Ć“âˆ‘ÂŽÂźâ€ Â„ÂšË†ĂžÏ€â€˜Ă„ĂŸâˆ‚Æ’Â©Ë™âˆ†ËšÂŹ", "MD5")
          ' c740ccc2e201df4b2e2b4aa086f35d8a
      

HtmlEncode

Encodes the input string into the HTML character codes, replacing special characters by their & counterparts.

For example, the character Ă© would be replaced by &eacute; or an equivalent numerical HTML code.

Syntaks:


        SF_String.HtmlEncode(InputStr) As String
      

Parametrar:

InputStr: The string to encode

Eksempel:


        MsgBox SF_String.HtmlEncode("<a href=""https://a.b.com"">From α to ω</a>")
        ' "&lt;a href=&quot;https://a.b.com&quot;&gt;From &#945; to &#969;&lt;/a&gt;"
      

IsADate

Returns True if the input string is a valid date according to a specified date format.

Syntaks:


        SF_String.IsADate(InputStr As String[, DateFormat As String]) As Boolean
      

Parametrar:

InputStr: The string to be checked. If empty, the method returns False

DateFormat: The date format, as a string. It can be either "YYYY-MM-DD" (default), "DD-MM-YYYY" or "MM-DD-YYYY"

The dash (-) may be replaced by a dot (.), a slash (/) or a space.

If the format is invalid, the method returns False.

Eksempel:


        MsgBox SF_String.IsADate("2020-12-31", "YYYY-MM-DD") ' True
      
note

This method checks the format of the input string without performing any calendar-specific checks. Hence it does not test the input string for leap years or months with 30 or 31 days. For that, refer to the IsDate built-in function.


The example below shows the difference between the methods IsADate (ScriptForge) and the IsDate (built-in) function.


    Dim myDate as String : myDate = "2020-02-30"
    MsgBox SF_String.IsADate(myDate, "YYYY-MM-DD") 'True
    MsgBox IsDate(myDate) 'False
  

IsAlpha

Returns True if all characters in the string are alphabetic.

Alphabetic characters are those characters defined in the Unicode Character Database as Letter.

Syntaks:


        SF_String.IsAlpha(InputStr As String) As Boolean
      

Parametrar:

InputStr: The string to be checked. If empty, the method returns False.

Eksempel:


        MsgBox SF_String.IsAlpha("àénΣlP”") 'True
        MsgBox SF_String.IsAlpha("myVar3") 'False
      

IsAlphaNum

Returns True if all characters in the string are alphabetic, digits or "_" (underscore). The first character must not be a digit.

Syntaks:


        SF_String.IsAlphaNum(InputStr As String) As Boolean
      

Parametrar:

InputStr: The string to be checked. If empty, the method returns False.

Eksempel:


        MsgBox SF_String.IsAlphaNum("_ABC_123456_abcàénΣlP”") 'True
        MsgBox SF_String.IsAlphaNum("123ABC") 'False
      

IsAscii

Returns True if all characters in the string are Ascii characters.

Syntaks:


        SF_String.IsAscii(InputStr As String) As Boolean
      

Parametrar:

InputStr: The string to be checked. If empty, the method returns False.

Eksempel:


        MsgBox SF_String.IsAscii("a%?,25") 'True
        MsgBox SF_String.IsAscii("abcàénΣlP”") 'False
      

IsDigit

Returns True if all characters in the string are digits.

Syntaks:


        SF_String.IsDigit(InputStr As String) As Boolean
      

Parametrar:

InputStr: The string to be checked. If empty, the method returns False.

Eksempel:


        MsgBox SF_String.IsDigit("123456") 'True
        MsgBox SF_String.IsDigit("_12a") 'False
      

IsEmail

Returns True if the string is a valid email address.

Syntaks:


        SF_String.IsEmail(InputStr As String) As Boolean
      

Parametrar:

InputStr: The string to be checked. If empty, the method returns False.

Eksempel:


        MsgBox SF_String.IsEmail("first.last@something.org") 'True
        MsgBox SF_String.IsEmail("first.last@something.com.br") 'True
        MsgBox SF_String.IsEmail("first.last@something.123") 'False
      

IsFileName

Returns True if the string is a valid filename in a given operating system.

Syntaks:


        SF_String.IsFileName(InputStr As String[, OSName As String]) As Boolean
      

Parametrar:

InputStr: The string to be checked. If empty, the method returns False.

OSName: The operating system name, as a string. It can be WINDOWS, LINUX, MACOSX or SOLARIS.

The default value is the current operating system on which the script is running.

Eksempel:


        MsgBox SF_String.IsFileName("~/Documents/a file name.odt", "LINUX") 'True
        MsgBox SF_String.IsFileName("C:\home\a file name.odt", "LINUX") 'False
        MsgBox SF_String.IsFileName("C:\home\a file name.odt", "WINDOWS") 'True
      

IsHexDigit

Returns True if all characters in the string are hexadecimal digits.

Syntaks:


        SF_String.IsHexDigit(InputStr As String) As Boolean
      

Parametrar:

InputStr: The string to be checked. If empty, the method returns False.

The hexadecimal digits may be prefixed with "0x" or "&H".

Eksempel:


        MsgBox SF_String.IsHexDigit("&H00FF") 'True
        MsgBox SF_String.IsHexDigit("08AAFF10") 'True
        MsgBox SF_String.IsHexDigit("0x18LA22") 'False
      

IsIBAN

Returns True if the string is a valid International Bank Account Number (IBAN). The comparison is not case-sensitive.

note

Denne metoden er tilgjengeleg frÄ LibreOffice 7.2 og nyare.


Syntaks:


        SF_String.IsIBAN(InputStr As String) As Boolean
      

Parametrar:

InputStr: The string to be checked. If empty, the method returns False.

Returverdi:

True if the string contains a valid IBAN number.

Eksempel:


        MsgBox SF_String.IsIBAN("BR15 0000 0000 0000 1093 2840 814 P2") 'returns True
      

IsIPv4

Returns True if the string is a valid IP(v4) address.

Syntaks:


        SF_String.IsIPv4(InputStr As String) As Boolean
      

Parametrar:

InputStr: The string to be checked. If empty, the method returns False.

Eksempel:


        MsgBox SF_String.IsIPv4("192.168.1.50") 'True
        MsgBox SF_String.IsIPv4("192.168.50") 'False
        MsgBox SF_String.IsIPv4("255.255.255.256") 'False
      

IsLike

Returns True if the whole input string matches a given pattern containing wildcards.

Syntaks:


        SF_String.IsLike(InputStr As String, Pattern As String[, CaseSensitive As Boolean) As Boolean
      

Parametrar:

InputStr: The string to be checked. If empty, the method returns False.

Pattern: The pattern as a string. Wildcard are:

CaseSensitive: Default = False.

Eksempel:


        MsgBox SF_String.IsLike("aAbB", "?A*") 'True
        MsgBox SF_String.IsLike("C:\a\b\c\f.odb", "?:*.*") 'True
        MsgBox SF_String.IsLike("name:host", "?*@?*") 'False
        MsgBox SF_String.IsLike("@host", "?*@?*") 'False
      

IsLower

Returns True if all characters in the string are in lowercase. Non-alphabetic characters are ignored.

Syntaks:


        SF_String.IsLower(InputStr As String) As Boolean
      

Parametrar:

InputStr: The string to be checked. If empty, the method returns False.

Eksempel:


        MsgBox SF_String.IsLower("abc'(-xy4z") 'True
        MsgBox SF_String.IsLower("1234") ' True
        MsgBox SF_String.IsLower("abcDefg") 'False
      

IsPrintable

Returns True if all characters in the string are printable.

Syntaks:


        SF_String.IsPrintable(InputStr As String) As Boolean
      

Parametrar:

InputStr: The string to be checked. If empty, the method returns False.

Eksempel:


        MsgBox SF_String.IsPrintable("Ă Ă©n ÎŁlP” РуссĐșĐžĐč") 'True
        MsgBox SF_String.IsPrintable("First line." & Chr(10) & "Second Line.") 'False
      

IsRegex

Returns True if the whole input string matches a given regular expression.

Syntaks:


        SF_String.IsRegex(InputStr As String, Regex As String[, CaseSensitive As Boolean) As Boolean
      

Parametrar:

InputStr: The string to be checked. If empty, the method returns False.

Regex: The regular expression. If empty, the method returns False.

CaseSensitive: Default = False.

Eksempel:


        MsgBox SF_String.IsRegex("aAbB", "[A-Za-z]+") ' True
        MsgBox SF_String.IsRegex("John;100", "[A-Za-z]+;[0-9]+") 'True
        MsgBox SF_String.IsRegex("John;100;150", "[A-Za-z]+;[0-9]+") 'False
      

IsSheetName

Returns True if the input string is a valid Calc sheet name.

Syntaks:


          SF_String.IsSheetName(InputStr As String) As Boolean
      

Parametrar:

InputStr: The string to be checked. If empty, the method returns False.

Eksempel:


          MsgBox SF_String.IsSheetName("1àbc + ""déf""") 'True
          MsgBox SF_String.IsSheetName("[MySheet]") 'False
      
note

A sheet name must not contain the characters [ ] * ? : / \ or the character ' (apostrophe) as first or last character.


IsTitle

Returns True if the first character of every word is in uppercase and the other characters are in lowercase.

Syntaks:


        SF_String.IsTitle(InputStr As String) As Boolean
      

Parametrar:

InputStr: The string to be checked. If empty, the method returns False.

Eksempel:


        MsgBox SF_String.IsTitle("This Is The Title Of My Book") 'True
        MsgBox SF_String.IsTitle("This is the Title of my Book") 'False
        MsgBox SF_String.IsTitle("Result Number 100") 'True
      

IsUpper

Returns True if all characters in the string are in uppercase. Non alphabetic characters are ignored.

Syntaks:


        SF_String.IsUpper(InputStr As String) As Boolean
      

Parametrar:

InputStr: The string to be checked. If empty, the method returns False.

Eksempel:


        MsgBox SF_String.IsUpper("ABC'(-XYZ") 'True
        MsgBox SF_String.IsUpper("A Title") 'False
      

IsUrl

Returns True if the string is a valid absolute URL (Uniform Resource Locator) address. Only the http, https and ftp protocols are supported.

Syntaks:


        SF_String.IsUrl(InputStr As String) As Boolean
      

Parametrar:

InputStr: The string to be checked. If empty, the method returns False.

Eksempel:


        MsgBox SF_String.IsUrl("http://foo.bar/?q=Test%20URL-encoded%20stuff") 'True
        MsgBox SF_String.IsUrl("www.somesite.org") 'False
      

IsWhitespace

Returns True if all characters in the string are whitespaces

Syntaks:


        SF_String.IsWhitespace(InputStr As String) As Boolean
      

Parametrar:

InputStr: The string to be checked. If empty, the method returns False.

Eksempel:


        MsgBox SF_String.IsWhitespace("    ") 'True
        MsgBox SF_String.IsWhitespace(" " & Chr(9) & Chr(10)) 'True
        MsgBox SF_String.IsWhitespace("") 'False
      

JustifyCenter

Returns the input string center-justified.

The leading and trailing white spaces are stripped and the remaining characters are completed left and right up to a specified total Length with the character Padding.

Syntaks:


        SF_String.JustifyCenter(InputStr As String[, Length As Long[, Padding As String]]) As String
      

Parametrar:

InputStr: The string to be center-justified. If empty, the method returns an empty string.

Length: The length of the resulting string (default = the length of the input string).

If the specified length is shorter than the center-justified input string, then the returned string is truncated.

Padding: The single character to be used as padding (default = the Ascii space " ").

Eksempel:


        MsgBox SF_String.JustifyCenter("Title", Length := 11) ' "   Title   "
        MsgBox SF_String.JustifyCenter("    ABCDE", Padding := "_") ' "__ABCDEF__"
        MsgBox SF_String.JustifyCenter("A Long Title", Length := 5) ' "ong T"
      

JustifyLeft

Returns the input string left-justified.

The leading white spaces are stripped and the remaining characters are completed to the right up to a specified total Length with the character Padding.

Syntaks:


        SF_String.JustifyLeft(InputStr As String[, Length As Long[, Padding As String]]) As String
      

Parametrar:

InputStr: Strengen som skal venstrejusterast. Viss tom, returnerer metoden ein tom streng.

Length: Lengda pÄ den resulterande strengen (standard = lengda pÄ inndatastrengen).

Viss den gjevne strengen er kortare enn den venstrejusterte inndatastrengen, vert den returnerte strengen avkorta.

Padding: Det enkeltteiknet som skal brukast som fyll (Standard = Ascii-mellomrommet « »).

Eksempel:


        MsgBox SF_String.JustifyLeft("Title", Length := 10) ' "Title     "
        MsgBox SF_String.JustifyLeft("    ABCDE", Padding := "_") ' "ABCDEF____"
        MsgBox SF_String.JustifyLeft("A Long Title", Length := 5) ' "A Lon"
      

JustifyRight

Returnerer inndata-strengen hĂžgrejustert.

Dei innleiande blankteikna vert fjerna og teikna som er igjen vert supplerte opp til den gjevne totalsummen Length (lĂŠngde) med teiknet Padding.

Syntaks:


        SF_String.JustifyRight(InputStr As String[, Length As Long[, Padding As String]]) As String
      

Parametrar:

InputStr: Strengen som skal hĂžgrejusterast. Viss tom, returnerer metoden ein tom streng.

Length: Lengda pÄ den resulterande strengen (standard = lengda pÄ inndatastrengen).

Viss den gjevne strengen er kortare enn den hĂžgrejusterte inndatastrengen, vert den returnerte strengen avkorta.

Padding: Det enkeltteiknet som skal brukast som fyll (Standard = Ascii-mellomrommet « »).

Eksempel:


        MsgBox SF_String.JustifyRight("Title", Length := 10) ' "     Title"
        MsgBox SF_String.JustifyRight("  ABCDE  ", Padding := "_") ' "____ABCDEF"
        MsgBox SF_String.JustifyRight("A Long Title", Length := 5) ' "Title"
      

Quote

Returnerer inndatastrengen mellom enkle eller doble sitatteikn. Sitatteikn som finst frÄ fÞr vert ikkje endra, inkludert innleiande og/eller avsluttande sitatteikn.

Syntaks:


        SF_String.Quote(InputStr As String, [QuoteChar As String]) As String
      

Parametrar:

InputStr: Strengen som skal setjast mellom sitatteikn.

QuoteChar : Anten enkle (') eller (standard) doble (") sitatteikn.

Eksempel:


        MsgBox SF_String.Quote("Text Value")
        ' "Text Value"
        MsgBox SF_String.Quote("Book Title: ""The Arabian Nights""", "'")
        ' 'Book Title: "The Arabian Nights"'
      
tip

Denne metoden kan vera nyttig nÄr du gjer klar eit strengfelt som skal lagrast i ei csv-liknande fil, noko som krev at tekstverdiar vert omgjevne av enkle eller doble sitatteikn.


ReplaceChar

Byter ut alle fĂžrekomstar av teikna som er gjevne i parameteren Before med dei tilsvarande teikna som er gjevne i After.

Viss lengda av Before er stĂžrre enn lengda av After, vert dei resterande teikna i Before bytt ut med det siste teiknet i After.

Syntaks:


        SF_String.ReplaceChar(InputStr As String, Before As String, After As String) As String
      

Parametrar:

InputStr: Inndata-strengen der bytinga skal skje.

Before: Ein streng med teikna som det skal sĂžkjast etter i inndatastrengen for Ă„ bytast ut.

After: Ein streng med nye teikn som skal bytast ut med dei som er definerte i Before.

Eksempel:


        ' Byter ut teikn med aksent
        MsgBox SF_String.ReplaceChar("ProtĂ©gez votre vie privĂ©e", "àùãçÚéĂȘĂ«ĂźĂŻĂŽĂ¶Ă»ĂŒĂœĂż", "aaaceeeeiioouuyy")
        ' "Protegez votre vie privee"
        MsgBox SF_String.ReplaceChar("ProtĂ©gez votre vie privĂ©e", "àùãçÚéĂȘĂ«ĂźĂŻĂŽĂ¶Ă»ĂŒĂœĂż", "")
        ' "Protgez votre vie prive"
        MsgBox SF_String.ReplaceChar("àùãçÚéĂȘĂ«ĂźĂŻĂŽĂ¶Ă»ĂŒĂœĂż", "àùãçÚéĂȘĂ«ĂźĂŻĂŽĂ¶Ă»ĂŒĂœĂż", "aaaceeeeiioouuyy")
        ' "aaaceeeeiioouuyy"
    

Tenesta SF_String inneheld nyttige delte konstantar for dei latinske teiknsetta, som vist i eksemplet nedanfor:


        MsgBox SF_String.ReplaceChar("Protégez votre vie privée", SF_String.CHARSWITHACCENT, SF_String.CHARSWITHOUTACCENT)
        ' "Protegez votre vie privee"
      

ReplaceRegex

Byter ut alle fĂžrekomstar av eit gjeve regulĂŠrt uttrykk med ein ny streng.

Syntaks:


        SF_String.ReplaceRegex(InputStr As String, Regex As String, NewStr As String[, CaseSensitive As Boolean]) As String
      

Parametrar:

InputStr: Inndata-strengen der bytinga skal skje.

Regex: Det regulĂŠre uttrykket.

NewStr: Strengen som erstattar.

CaseSensitive: Standard = Usann.

Eksempel:


          MsgBox SF_String.ReplaceRegex("Lorem ipsum dolor sit amet, consectetur adipiscing elit.", "[a-z]", "x", CaseSensitive := True)
          ' "Lxxxx xxxxx xxxxx xxx xxxx, xxxxxxxxxxx xxxxxxxxxx xxxx." (kvar liten bokstav er erstatta med «x»)
          MsgBox SF_String.ReplaceRegex("Lorem ipsum dolor sit amet, consectetur adipiscing elit.", "\b[a-z]+\b", "x", CaseSensitive := False)
          ' "x x x x x, x x x." kvart ord er erstatta med «x»)
      

ReplaceStr

Byter ut nokre eller alle fĂžrekomstane av ei matrise med strengar med ei matrise med nye strengar.

Syntaks:


        SF_String.ReplaceStr(InputStr As String, OldStr As Variant, NewStr As Variant[, Occurrences As Long[, CaseSensitive As Boolean]]) As String
      

Parametrar:

InputStr: Inndata-strengen der bytinga skal skje.

OldStr: Ein enkelt streng eller ei matrise av strengar. Strengar med null-lengde vert ignorerte.

NewStr: Erstatningsstrengen eller ei matrise av erstatningsstrengar.

Viss OldStr er ei matrise, vert kvar fĂžrekomst av kva element som helst i OldStr bytt ut med NewStr.

Viss OldStr og NewStr er matriser, skjer bytinga ein etter ein opp til UBound(NewStr).

Viss OldStr har fleire oppfĂžringar enn NewStr, vert restelementa i OldStr bytt ut med det siste elementet i NewStr.

Occurrences: Det hÞgste talet pÄ erstatningar. Standardverdien er 0, som gjer at alle fÞrekomstane vert bytt ut.

NÄr OldStr er ei matrise, vert parameteren Occurrence rekna ut enkeltvis for kvart element i matrisa.

CaseSensitive: Standard = Usann.

Eksempel:


        MsgBox SF_String.ReplaceStr("100 xxx 200 yyy", Array("xxx", "yyy"), Array("(1)", "(2)"), CaseSensitive := False)
        ' "100 (1) 200 (2)"
        MsgBox SF_String.ReplaceStr("abCcdefghHij", Array("c", "h"), Array("Y", "Z"), CaseSensitive := False)
        ' "abYYdefgZZij"
      

Represent

Returnerer ein streng med ein lesbar representasjon av argumentet, avkorta til ei gjeve lengde. Dette er nyttig stort sett for feilsÞkings- eller loggingsfÞremÄl.

Viss parameteren AnyValue er eit objekt, vert det omgjeve av hakeparentesane «[» og «]».

I strengar vert tabulatorar og linjeskift byt ut med \t, \n eller \r.

Viss den endelege lengda er stĂžrre enn MaxLength-parameteren, vert den siste delen av strengen erstatta med « 
 (N)» der N er den totale lengda pĂ„ den opphavlege strengen fĂžr avkortinga.

Syntaks:


        SF_String.Represent(AnyValue As Variant[, MaxLength As Long]) As String
      

Parametrar:

AnyValue: Inndataverdien som skal representerast. Det kan vera kva verdi som helst, for eksempel ein streng, ei matrise, eit Basic-objekt, eit UNO-objekt osv.

MaxLength: Den maksimale lengda pÄ den resulterande strengen. Standardverdien er 0, som gjer at det ikkje er noko grense for lengda pÄ den resulterande representasjonen.

Eksempel:


        MsgBox SF_String.Represent("this is a usual string") ' "this is a usual string"
        MsgBox SF_String.Represent("this is a usual string", 15) ' "this i ... (22)"
        MsgBox SF_String.Represent("this is a" & Chr(10) & " 2-lines string") ' "this is a\n 2-lines string"
        MsgBox SF_String.Represent(Empty) ' "[EMPTY]"
        MsgBox SF_String.Represent(Null) ' "[NULL]"
        MsgBox SF_String.Represent(Pi) ' "3.142"
        MsgBox SF_String.Represent(CreateUnoService("com.sun.star.util.PathSettings")) ' "[com.sun.star.comp.framework.PathSettings]"
      

Legg merke til at representasjonen av datatypar som matriser og ScriptForge.Dictionary objektfÞrekomstar inkluderer bÄde datatypen og verdiane:


    ' Et eksempel med ei innebygd Basic-matrise
    MsgBox SF_String.Represent(Array(1, 2, "Text" & Chr(9) & "here"))
    ' "[ARRAY] (0:2) (1, 2, Text\there)"
    ' Eit eksempel med ei ScriptForge-matrise
    Dim aValues as Variant
    aValues = SF_Array.RangeInit(1, 5)
    MsgBox SF_String.Represent(aValues)
    ' "[ARRAY] (0:4) (1.0, 2.0, 3.0, 4.0, 5.0)"
    ' Eit eksempel med ei ScriptForge-ordbok
    Dim myDict As Variant : myDict = CreateScriptService("Dictionary")
    myDict.Add("A", 1) : myDict.Add("B", 2)
    MsgBox SF_String.Represent(myDict)
    ' "[Dictionary] ("A":1, "B":2)"
  

Reverse

Returnerer inndata-strengen i omvendt rekkjefĂžlgje.

Denne metoden svarar til den innebygde Basic-funksjonen StrReverse, men med betre yting.

note

For Ä bruka funksjonen StrReverse mÄ uttrykket OpTion VBASupport 1 vera tilstades i modulen.


Syntaks:


        SF_String.Reverse(InputStr As String) As String
      

Parametrar:

InputStr: Strengen som skal reverserast.

Eksempel:


        MsgBox SF_String.Reverse("abcdefghij") ' "jihgfedcba"
      

SplitLines

Returnerer ei null-basert matrise av strengar med linjene i inndatastrengen. Kvart element i matrisa vert hent ved Ă„ dela inndatastrengen ved linjeskiftteikna.

Syntaks:


        SF_String.SplitLines(InputStr As String[, KeepBreaks As Long]) As Variant
      

Parametrar:

InputStr: Strengen som skal delast.

KeepBreaks: NÄr Sann vert linjeskift ikkje endra i utdatamatrisa (standard = Usann).

Eksempel:


        Dim a as Variant
        a = SF_String.SplitLines("Line1" & Chr(10) & "Line2" & Chr(13) & "Line3")
        ' a = Array("Line1", "Line2", "Line3")
        a = SF_String.SplitLines("Line1" & Chr(10) & "Line2" & Chr(13) & "Line3" & Chr(10))
        ' a = Array("Line1", "Line2", "Line3", "")
        a = SF_String.SplitLines("Line1" & Chr(10) & "Line2" & Chr(13) & "Line3" & Chr(10), KeepBreaks := True)
        ' a = Array("Line1\n", "Line2\r", "Line3\n", "")
      

SplitNotQuoted

Deler ein streng inn i ei matrise av element ved hjelp av eit spesifisert skiljeteikn.

Viss ein delstreng sett mellom sitatteikn inneheld eit skiljeteikn, vert skiljeteiknet ignorert. Dette er nyttig nÄr du analyserer CSV-liknande oppfÞringar som inneheld strengar i sitatteikn.

Syntaks:


        SF_String.SplitNotQuoted(InputStr As String[, Delimiter As String], [Occurrences As Long], [QuoteChar As String]) As Variant
      

Parametrar:

InputStr: Strengen som skal delast.

Delimiter: Ein streng med eitt eller fleire teikn som skal brukast som skiljeteikn. Standard-skiljeteiknet er mellomromsteiknet.

Occurrences: Det hÞgste talet pÄ understrengar som skal returnerast. Standardverdien er 0, som betyr at det ikkje er noko grense for kor mange returnerte strengar.

QuoteChar : Either the single (') or double (") quote.

Eksempel:


        a = SF_String.SplitNotQuoted("abc def ghi")
        ' a = Array("abc", "def", "ghi")
        a = SF_String.SplitNotQuoted("abc,""def,ghi""", ",")
        ' a = Array("abc", """def,ghi""")
        a = SF_String.SplitNotQuoted("abc,""def\"",ghi""", ",")
         ' a = Array("abc", """def\"",ghi""")
        a = SF_String.SplitNotQuoted("abc,""def\"",ghi"""",", ",")
        ' a = Array("abc", """def\"",ghi""", "")
      

StartsWith

Returns True if the first characters of a string are identical to a given substring.

This method returns False if either the input string or the substring have a length = 0 or when the substring is longer than the input string.

Syntaks:


        SF_String.StartsWith(InputStr As String, Substring As String[, CaseSensitive As Boolean]) As Boolean
      

Parametrar:

InputStr: The string to be tested.

Substring: The substring to be searched at the start of InputStr.

CaseSensitive: Default = False.

Eksempel:


        MsgBox SF_String.StartsWith("abcdefg", "ABC") 'True
        MsgBox SF_String.StartsWith("abcdefg", "ABC", CaseSensitive := True) 'False
      

TrimExt

Returns the input string without its leading and trailing whitespaces.

Syntaks:


        SF_String.TrimExt(InputStr As String) As String
      

Parametrar:

InputStr: The string to trimmed.

Eksempel:


        MsgBox SF_String.TrimExt(" Some text.  ") ' "Some text."
        MsgBox SF_String.TrimExt("   ABCDE" & Chr(9) & Chr(10) & Chr(13) & " ") ' "ABCDEF"
      

Unescape

Converts any escaped sequence (\\, \n, \r, \t) in the input string to their corresponding Ascii character.

Syntaks:


        SF_String.Unescape(InputStr As String) As String
      

Parametrar:

InputStr: The string to be converted.

Eksempel:


        MsgBox SF_String.Unescape("abc\n\tdef\\n")
        ' "abc" & Chr(10) & Chr(9) & "def\n"
      

Unquote

Removes the single or double quotes enclosing the input string.

This is useful when parsing CSV-like records that contain quoted strings.

Syntaks:


        SF_String.Unquote(InputStr As String, [QuoteChar As String]) As String
      

Parametrar:

InputStr : The string to unquote.

QuoteChar : Either the single (') or double (") quote (default).

Eksempel:


        Dim s as String
        s = SF_String.Unquote("""Some text""") ' s = "Some text" (without enclosing quotes)
        ' The string below does not have enclosing quotes, so it remains unchanged
        s = SF_String.Unquote("Some text") ' s = "Some text" (unchanged)
        ' Quotes inside the string are not removed
        s = SF_String.Unquote("The ""true"" meaning") ' s = "The ""true"" meaning"
      

Wrap

Converts the input string into an array of substrings so that each item in the array has at most a given number of characters.

In practice, this method returns a zero-based array of output lines, without newlines at the end, except for the pre-existing line-breaks.

Tabs are expanded using the same procedure performed by the ExpandTabs method.

Symbolic line breaks are replaced by their equivalent Ascii characters.

If the wrapped output has no content, the returned array is empty.

Syntaks:


          SF_String.Wrap(InputStr As String, [Width As Long], [TabSize As Integer]) As String
      

Parametrar:

InputStr: The string to wrap.

Width : The maximum number of characters in each line (default = 70).

TabSize : Before wrapping the text, the existing TAB Chr(9) characters are replaced with spaces. TabSize defines the TAB stops at TabSize + 1, 2 * TabSize + 1 , ... N * TabSize + 1 (default = 8).

Eksempel:


          a = "Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."
          b = SF_String.Wrap(a, 20)
          ' Array("Neque porro ", "quisquam est qui ", "dolorem ipsum quia ", "dolor sit amet, ", "consectetur, ", "adipisci velit...")
        
warning

Alle Basic-rutinane og -identifikatorane i ScriptForge som vert innleidde med understrek «_» er reserverte for internt bruk. Dei er ikkje tenkt brukte i Basic-makroar.