Results for “Strings & Unicode”
Small, practical examples. Search by task or narrow things down below.
Represent a finite set of states
Java: Use an enum to prevent arbitrary strings from representing application states.
Java✓ Tested
Reverse a string
Reverse a byte string in place with std::reverse.
C++✓ Tested
Round decimal amounts explicitly
Python: Build Decimal values from strings and choose a rounding rule explicitly.
Python✓ Tested
Split a string into words
Split text on whitespace, automatically treating repeated spaces, tabs, and line breaks as a single separator.
string✓ Tested
Split and trim text
Split simple comma-separated JavaScript text and trim each part.
JavaScript✓ Tested
Split and trim values
Split simple comma-separated C# text and trim each value.
C#✓ Tested
Split comma-separated text
Split a simple comma-separated string into individual Java values.
Java✓ Tested
Split comma-separated text
Use getline with a delimiter to split simple C++ text.
C++✓ Tested
Test whether an array contains a value
PowerShell: The contains operator compares complete items rather than matching substrings.
PowerShell✓ Tested
Trim surrounding whitespace
Remove whitespace at the ends of a C# string.
C#✓ Tested
Trim surrounding whitespace
Remove leading and trailing whitespace from a Java string.
Java✓ Tested
Trim surrounding whitespace
Remove leading and trailing JavaScript string whitespace.
JavaScript✓ Tested