Skip to content

Instantly share code, notes, and snippets.

@CHatmaker
Created September 24, 2025 01:06
Show Gist options
  • Select an option

  • Save CHatmaker/9233ebd98e0d7138364898bf11ea47c2 to your computer and use it in GitHub Desktop.

Select an option

Save CHatmaker/9233ebd98e0d7138364898bf11ea47c2 to your computer and use it in GitHub Desktop.
BXL 5g Functions LAMBDA Text
/* Text Function - A collection of functions for working with text.*/
/* FUNCTION NAME: Aboutλ
DESCRIPTION:*//**Displays the URL to this module's Gist which includes documentation*/
/* REVISIONS: Date Developer Description
Aug 23 2025 Craig Hatmaker Copyright
*/
Aboutλ = TRIM(TEXTSPLIT(
"About: →A collection of functions for working with text. Suggested module name: TXT¶" &
"Version: →BXL: Aug 23 2025¶" &
"Gist URL: →https://gist.github.com/CHatmaker/d0829c4bde303f5f8602c21158831323 ¶" &
"Website: →https://sites.google.com/site/beyondexcel/home/excel-library/ ¶" &
"→¶" &
"Function →Description¶" &
" Aboutλ →Produces this table¶" &
" CountCλ →Count how many of one or more characters are in a text string¶" &
" RevTextλ →Reverse the characters in a text string¶" &
" TextToArrayλ →Convert a string of text into an array of characters¶" &
" StringDiffsλ →Compare two strings and show differences.",
"→","¶"
)
);
/* FUNCTION NAME: CountCλ
DESCRIPTION:*//**Count occurences of character(s) in a string*/
/* REVISIONS: Date Developer Description
Feb 23 2024 Craig Hatmaker Copyright
*/
CountCλ = LAMBDA(
// Parameter Declarations
[Text],
[Characters],
// Help
LET(Help, TRIM(TEXTSPLIT(
"FUNCTION: →CountCλ( Text, Characters)¶" &
"DESCRIPTION: →Count how many of one or more characters are in a string.¶" &
"WEBPAGE: →https://sites.google.com/site/beyondexcel/home/5g-modeling/¶" &
"→5g-component-libraries/5g-array-essentials-library/5g-countc%CE%BB¶" &
"VERSION: →BXL: Feb 23 2024¶" &
"PARAMETERS: →¶" &
" Text →(Required) The string to interrogate¶" &
" Characters →(Required) A single character, or CSV of characters to find in Text¶" &
"→NOTE! Case sensitive.",
"→", "¶" )
),
// Check inputs - Omitted required arguments
Help?, OR( ISOMITTED( Text),
ISOMITTED( Characters)
),
// Procedure
fnCountC, LAMBDA( Text, Characters,
LEN(Text) - SUM( LEN( TEXTSPLIT( Text, TEXTSPLIT( Characters, "," ))))),
Result, MAP( Text, Characters, fnCountC),
// Return Result
IF(Help?, Help, Result)
)
);
/* FUNCTION NAME: RevTextλ
DESCRIPTION:*//**Reverse the characters in a text string*/
/* REVISIONS: Date Developer Description
Aug 13 2025 Craig Hatmaker Copyright
*/
RevTextλ = LAMBDA(
[Text],
LET(
// Help
Help, TRIM(TEXTSPLIT(
"FUNCTION: →RevTextλ( Text)¶" &
"DESCRIPTION: →Reverse the characters in a text string¶" &
"WEBPAGE: →<coming soon>¶" &
"VERSION: →BXL: Aug 13 2025¶" &
"PARAMETERS: →¶" &
" Text →(Required) Text to reverse.",
"→", "¶"
)
),
// Check inputs - Omitted required arguments
Help?, ISOMITTED( Text),
// Procedure
Count, LEN( Text),
Result, MAP( Text,
LAMBDA( Text ,
LET(
Count, LEN( Text),
Reverse, SEQUENCE( Count, , Count, -1),
Result, CONCAT( MID( Text, Reverse, 1)),
Result
)
)
),
// Return Result or help
IF(Help?, Help, Result)
)
);
/* FUNCTION NAME: StringDiffsλ
DESCRIPTION:*//**Compare 2 strings and show the differences*/
/* REVISIONS: Date Developer Description
Aug 13 2025 Craig Hatmaker Copyright
*/
StringDiffsλ = LAMBDA(
[String1],
[String2],
LET(
// Help
Help, TRIM(TEXTSPLIT(
"FUNCTION: →StringDiffsλ( String1, String2)¶" &
"DESCRIPTION: →Compare two strings and show differences.¶" &
"WEBPAGE: →<coming soon>¶" &
"VERSION: →BXL: Aug 13 2025¶" &
"PARAMETERS: →¶" &
" String1 →(Required) First text string.¶" &
" String2 →(Required) Second text string.",
"→", "¶"
)
),
// Check inputs - Omitted required arguments
Help?, ISOMITTED( Text), // Define function string to array
// Define function to convert a string to an array
fnStr2Ary, LAMBDA(
Text,
LET(
Counter, SEQUENCE( , LEN( Text)),
Result, MAP( Counter, LAMBDA( n, MID( Text, n, 1))),
Result
)
),
// Procedure
Array1, fnStr2Ary( String1),
Array2, fnStr2Ary( String2),
Array, IFNA( VSTACK( Array1, Array2), ""),
Counter, SEQUENCE( COLUMNS( Array)),
Diffs, REDUCE( 0, Counter,
LAMBDA( Acc, n,
LET(
Char1, INDEX( Array, 1, n),
Char2, INDEX( Array, 2, n),
Column, IF( Char1 = Char2,
VSTACK( ".", "." ),
VSTACK( Char1, Char2)
),
Result, IF( n = 1, Column, HSTACK( Acc, Column)),
Result
)
)
),
Result, VSTACK( CONCAT( TAKE( Diffs, 1)), CONCAT( TAKE( Diffs, -1))),
// Return Result or help
IF(Help?, Help, Result)
)
);
/* FUNCTION NAME: TextToArrayλ
DESCRIPTION:*//**Convert a string to an array of characters*/
/* REVISIONS: Date Developer Description
Aug 13,2025 Craig Hatmaker Copyright
*/
TextToArrayλ = LAMBDA(
[Text],
LET(
// Help
Help, TRIM(TEXTSPLIT(
"FUNCTION: →TextToArrayλ( Text)¶" &
"DESCRIPTION: →Convert a string to an array of characters¶" &
"WEBPAGE: →<coming soon>¶" &
"VERSION: →BXL: Aug 13 2025¶" &
"PARAMETERS: →¶" &
" Text →(Required) Text to convert to an array.",
"→", "¶"
)
),
// Check inputs - Omitted required arguments
Help?, ISOMITTED( Text),
// Procedure
Counter, SEQUENCE( , LEN( Text)),
Result, MAP( Counter, LAMBDA( n, MID( Text, n, 1))),
// Return Result or help
IF(Help?, Help, Result)
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment