String (package) - MrKaszeba19/PapajLang GitHub Wiki

String is a package of functions for PapajScript. This package contains functions that work with text strings. It was released on May 5, 2020.

The earliest known stable RPN Calculator version to work with String – 0.4.3.

List of String functions

Notes:

  • If you do not want to type String. every time, just type @use(String) before. However, if you want to stop using the package, type @unuse(String).
  • Since October 1, 2020 (stable version 0.5.1) the strings are zero-based and evaluated in C-like style by default (it may be changed by @stringstart directive). It means the first index of a string is not 1, but 0.
  • The version 0.5.1.1 is the last version where you can use String. functions without running @use(String). Starting from April 16, 2021, all String functions require to be activated by @use(String)
Package Function Syntax Output type Purpose Since
String.apostrophed STR1 function String Enclose the string with a single quote (apostrophe) like 'this' 0.5.2
String.apostrophed2 STR1 function String Enclose the string with a single quote (apostrophe) like 'this'. Existing apostrophes would be double-apostrophed 0.5.2.1
String.between STR1 NUM1 NUM2 function String Extracts a substring from a string S1 positioned between N1 and N2 0.4.3
String.bind STR1 STR2 function String Concatenates two strings with a delimiter of a space char 0.4.3
String.bindBy STR1 STR2 STR3 function String Concatenates two strings S1 S2 with a delimiter of a S3 delimiter 0.4.3
String.compare STR1 STR2 function Number Returns 0 if S1=S2, -1 if S1<S2, or 1 if S1>S2 0.5.1
String.concat STR1 STR2 function String Concatenates two strings 0.4.3
String.copies STR1 NUM1 function String Returns a string which consists of N1 concatenated copies of S1 0.5.2
String.crush STR1 function set of String Splits a string S1 to single chars 0.4.3
String.crushBy STR1 NUM1 function set of String Splits a string S1 to the parts of the same length of N1 (except for the last part, if len(S1) is not divisible by N1) 0.4.3
String.cut STR EXP1 function String Return a string with all chars that do not meet the E1 condition 0.5.2
String.cutBothSides STR1 NUM1 NUM2 function String Return a string that has cut the first N1 and the last N2 chars of S1 string 0.5.1
String.cutLeft STR1 NUM1 function String Return a string that has cut the first N1 chars of S1 string 0.5.1
String.cutRight STR1 NUM1 function String Return a string that has cut the last N1 chars of S1 string 0.5.1
String.dechar STR1 STR2 function String Removes all chars of S2 from a string S1 0.4.3
String.delete STR1 STR2 function String Removes the last occurence a substring S2 from a string S1 0.5.2
String.delete STR1 NUM1 function String Removes the last N1 characters from a string S1 0.5.2
String.divide STR1 STR2 function String Removes all occurences a substring S2 from a string S1 0.5.2
String.divide STR1 NUM1 function String Cuts a string S1 by dividing its length by N1 0.5.2
String.despace STR1 function String Eliminates space chars 0.4.3
String.enclosed STR1 STR2 function String If S2 contains 1 char, then enclose a S1 string with S2's char. If S2 contains 2 chars, then enclose a S1 string with the S2's first char on the left and S2's second one on the right 0.5.2
String.eval STR1 function none * Runs a string like it was a PS script 0.5.1
String.filter STR EXP1 function String Return a string with all chars that meet the E1 condition 0.5.2
String.first STR1 function String Return the first char of S1 0.5.2
String.getAt STR1 NUM1 function Char = String(1) Get the N1-th character of S1 0.5.1
String.inC STR1 String.inC String Get a C/C++/Java-like formatted string (with \t, \n etc.) and transform it by inserting respective ASCII chars. It is useful when having Pascal string mode on 0.4.3
String.insert STR1 STR2 NUM1 function String Inserts a string S2 into the string S1 in the position N1, making the following chars shift right 0.4.3
String.isEmpty STR1 function String Determine if the string is empty (has no chars) 0.5.2
String.join STR1 STR2 function String Concatenates two strings (String.concat alias) 0.5.1
String.left STR1 NUM1 function String Extracts a substring from a string S1 of the first N1 letters 0.4.3
String.last STR1 function String Return the last char of S1 0.5.2
String.length STR1 function Number Gets string length 0.4.3
String.lower STR1 function String Converts all uppercase letters to lowercase 0.5.1
String.map STR1 FUN1 function String Apply a F1 function to each char of a string 0.5.2
String.nthOccur STR1 STR2 NUM1 function Number Returns an index of the N1-th occurence of a substring S2 in a string S1 0.4.3
String.occurs STR1 STR2 function Number Returns a count of occurences of a substring S2 in a string S1 0.4.3
String.onespace STR1 function String Eliminates combo space chars (e.g. "2 3" -> "2 3") 0.4.3
String.pad STR1 NUM1 function String Fills a S1 string with spaces to reach the length of N1, and the string is centered 0.4.3
String.padLeft STR1 NUM1 function String Fills a S1 string with spaces to reach the length of N1, and the string is right-justified 0.4.3
String.padRight STR1 NUM1 function String Fills a S1 string with spaces to reach the length of N1, and the string is left-justified 0.4.3
String.padChars STR1 CHR1 NUM1 function String Fills a STR1 string with copies of CHR1 to reach the length of NUM1, and the string is centered 0.5.2
String.padCharsRight STR1 CHR1 NUM1 function String Fills a STR1 string with copies of CHR1 to reach the length of NUM1, and the string is right-justified 0.5.2
String.padCharsLeft STR1 CHR1 NUM1 function String Fills a STR1 string with copies of CHR1 to reach the length of NUM1, and the string is left-justified 0.5.2
String.positionFirst STR1 STR2 function Number Returns the position of the first occurence of a substring S2 in a string S1 0.4.3
String.positionFrom STR1 STR2 NUM1 function Number Returns the position of the next occurence of a substring S2 in a string S1, starting from N1 position 0.4.3
String.positionLast STR1 STR2 function Number Returns the position of the last occurence of a substring S2 in a string S1 0.4.3
String.quoted STR1 function String Enclose the string with a quote like "this" 0.5.2
String.quoted2 STR1 function String Enclose the string with a quote like "this". Existing quote chars would be doubled. 0.5.2.1
String.reduce STR1 FUN1 ENT1 function Entity Reduce S1 left-to-right to single value using a binary function F1, starting with a E1 entity as initial value of an accumulator 0.5.2
String.reduceLeft STR1 FUN1 ENT1 function Entity Same as String.reduce 0.5.2
String.reduceRight STR1 FUN1 ENT1 function Entity Reduce S1 right-to-left to single value using a binary function F1, starting with a E2 entity as initial value of an accumulator 0.5.2
String.reduceFromFirst STR1 FUN1 function Entity Reduce S1 left-to-right to single value using a binary function F1, starting with S1's first char as an initial value of an accumulator 0.5.2
String.reduceLeftFromFirst STR1 FUN1 function Entity Same as String.reduceFromFirst 0.5.2
String.reduceRightFromLast STR1 FUN1 function Entity Reduce S1 right-to-left to single value using a binary function F1, starting with S1's last char as an initial value of an accumulator 0.5.2
String.remove STR1 STR2 function String Removes the first occurence a substring S2 from a string S1 0.4.3
String.remove STR1 NUM1 NUM2 function String Removes a substring from a string S1, starting in N1 and being N2 chars long 0.4.3
String.replace STR1 STR2 NUM1 function String Inserts a string S2 into the string S1 in the position N1, making the following chars be replaced 0.4.3
String.right STR1 NUM1 function String Extracts a substring from a string S1 of the last N1 letters 0.4.3
String.setAt STR1 NUM1 CHR1 function String Return a string that has a C1 char inserted into a S1 string in the position of N1 0.5.1
String.split STR1 NUM1 function set(2) of String Splits the S1 string to two parts, where the latter parts starts with N1-th char 0.5.1
String.splitBy STR1 STR2 function set of String Splits the S1 string according to a char of S2 (and a space char too, S2 must be a single char) 0.4.3
String.splitByExpression STR1 EXP1 function set(2) of String Splits the S1 string to two strings using E1 expression 0.5.3
String.splitBySpace STR1 function set of String Splits a string according to space chars 0.5.1
String.strPos STR1 STR2 function Number Returns an index of the first occurence of a substring S2 in a string S1 0.4.3
String.strreduce STR1 FUN1 STR2 function String Reduce S1 left-to-right to single value using a binary function F1, starting with a S2 string as initial value of an accumulator 0.5.2
String.strreduceLeft STR1 FUN1 STR2 function String Same as String.strreduceLeft 0.5.2
String.strreduceRight STR1 FUN1 STR2 function String Reduce S1 right-to-left to single value using a binary function F1, starting with a S2 string as initial value of an accumulator 0.5.2
String.strreduceFromFirst STR1 FUN1 function String Reduce S1 left-to-right to single value using a binary function F1, starting with S1's first char as an initial value of an accumulator 0.5.2
String.strreduceLeftFromFirst STR1 FUN1 function String Same as String.strreduceLeftFromFirst 0.5.2
String.strreduceRightFromLast STR1 FUN1 function String Reduce S1 right-to-left to single value using a binary function F1, starting with S1's last char as an initial value of an accumulator 0.5.2
String.substring STR1 NUM1 NUM2 function String Extracts a substring from a string S1, starting in N1 and being N2 chars long 0.4.3
String.translate STR1 STR2 STR3 function String Translates the S1's chars using the map between the chars of S2 and the chars of S3. All S1's chars that match the N-th char of S2 will be translated to the N-th char of S3. Note that the lengths of S2 and S3 must be the same. 0.5.2
String.trim STR1 function String Eliminates whitespace on the both left and right sides 0.4.3
String.trimLeft STR1 function String Eliminates whitespace on the left side 0.4.3
String.trimRight STR1 function String Eliminates whitespace on the right side 0.4.3
String.trimChars STR1 CHR1 function String Removes all occurences of CHR1 char from the both sides of STR1 string 0.5.2
String.trimCharsRight STR1 CHR1 function String Removes all occurences of CHR1 char from the right side of STR1 string 0.5.2
String.trimCharsLeft STR1 CHR1 function String Removes all occurences of CHR1 char from the left side of STR1 string 0.5.2
String.uplower STR1 function String Converts all uppercase letters to lowercase and makes first char uppercase 0.5.1
String.upper STR1 function String Converts all lowercase letters to uppercase 0.5.1
String.value STR1 function Number/String Converts to a number (if possible) 0.4.3

* – except for anything the script returns

Obsolete functions

Package Function Syntax Output type Purpose Since Latest supported version
String.run STR1 function none * Runs a string like it was a PS script (replaced by String.eval) 0.4.3 0.5.0
String.split STR1 function set of String Splits a string according to space chars (replaced by String.splitBySpace) 0.4.3 0.5.0
String.system STR1 function String Execute a command being included in S1 0.4.3 0.5.1.2

* – except for anything the script returns

Examples

  • "Hello\tworld!\n" String.inC returns a string Hello        world! with a tab between words and begins a new line (assuming the script works in Pascal mode).
  • " abc def " String.trim returns "abc def".
  • "ls" String.system executes ls (assuming RPN uses bash)
  • "hello" -> $abc assigns hello string to a abc variable,
    then $abc 1 getAt println prints e (a abc's char of index 1)
    and finally $abc 1 "*" String.setAt -> $abc creates a string with * inserted at the index 1 of abc (the string is h*llo), which is assigned to a variable abc
  • "abcdef" "$" enclosed returns $abcdef$
  • "abcdef" "\'" enclosed returns 'abcdef'
  • "abcdef" "{}" enclosed returns {abcdef}
  • "abcdef" fun{ getAscii 3 + makeChar } map returns defghi
  • "abcdef" ( getAscii 2 mod 1 = ) filter returns ace
  • "abcdefghijkl" "degf" "0123" String.translate returns abc0132hijkl