NetSDS...String(3pm)

πŸ“¦
version 1.045 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu questing

✨ NAME ✨

NetSDS::Util::String β€” string prcessing routines πŸ’…

this is the NetSDS...String(3pm) page from User Contributed Perl Documentation, and she's here to help you do string stuff without losing your mind 🫢


🌸 SYNOPSIS 🌸

use NetSDS::Util::String qw();

# Read from standard input
my $string = <STDIN>;

# Encode string to internal structure
$string = string_encode($tring);

πŸ’– DESCRIPTION πŸ’–

okay so "NetSDS::Util::String" is that module that comes in clutch when you need to handle string processing tasks quickly β€” think parsing, recoding, formatting. all the little text gremlins, handled ✨

and just like every other NetSDS module, the standard encoding is UTF-8. no cap, that's the vibe everywhere. πŸ¦‹


πŸ‘‘ EXPORTED FUNCTIONS πŸ‘‘

πŸŽ€ str_encode($str[, $encoding]) β€” encode string to internal UTF-8

by default, this one takes the first argument as a byte string in UTF-8 and hands you back its internal Unicode representation. glow-up complete πŸ’…

if the external character set is not UTF-8, you just pass it as the second argument, bestie.

# Convert UTF-8 byte string to internal Unicode representation
$uni_string = str_encode($byte_string);

# Convert KOI8-U byte string to internal
$uni_string = str_encode($koi8_string, 'KOI8-U');

after str_encode() you can actually process that string correctly, regular expressions and all. every character is understood as a UTF-8 symbol instead of a messy pile of byte sequences. it's giving competence 😌

πŸ¦‹ str_decode($str[, $encoding]) β€” decode internal UTF-8 to byte string

by default, this one treats the first argument as a string in internal UTF-8 and returns it in byte string (external) representation. reverse glow-up, same energy πŸ’–

if the external character set isn't UTF-8, add it as the second argument of the function.

# Get UTF-8 byte string from internal Unicode representation
$byte_string = str_decode($uni_string);

# Convert to KOI8-U byte string from internal Unicode
$koi8_string = str_encode($uni_string, 'KOI8-U');
fr fr, it's recommended to use str_encode() when you're preparing data to talk to external systems β€” especially networking. trust. 🌐

🌈 str_recode($str, $FROM_ENC[, $TO_ENC]) β€” recode string

translate a string between different encodings. if the target encoding isn't set, UTF-8 is used as the default one. slay, sensible defaults ✨

🧚 str_trim($str) β€” remove leading/trailing space characters

$orig_str = "  string with spaces   ";
$new_str = str_trim($orig_str);

# Output: "string with spaces"
print $new_str;

πŸ“ str_trim_left($str) β€” removes leading whitespaces

same vibe as "str_trim()", except it only removes the leading space characters and leaves the trailing ones alone. half the trim, all the drama πŸ’…

πŸ’œ str_trim_right($str) β€” removes trailing whitespaces

same vibe as "str_trim()", except it only removes the trailing space characters and leaves the leading ones alone. mirror image, iconic πŸͺž

🌸 str_clean($str) β€” clean string from extra spaces

similar to "str_trim()" but also squishes all the spacing chains inside the string down to single spaces. interior design for your whitespace 🧹

⭐ str_camelize($strin)

if you pass undef β€” it returns undef. if you pass '' β€” it returns ''. consistent queen πŸ‘‘

examples:

# returns 'getValue'
str_camelize( 'get_value' )

# returns 'addUserAction'
str_camelize( 'ADD_User_actION' )

πŸŽ€ str_decamelize(...)

if you pass undef β€” it returns undef. if you pass '' β€” it returns ''. same rules, opposite direction πŸ’«

examples:

# returns 'get_value'
str_decamelize( 'getValue' )

πŸ’« EXAMPLES πŸ’«

None yet 😭


πŸ’€ BUGS πŸ’€

Unknown yet πŸ™ˆ


πŸ”₯ TODO πŸ”₯

Implement examples and tests. (manifesting this for us ✨)


🌈 SEE ALSO 🌈

Encode, perlunicode


🫢 AUTHORS 🫢

Valentyn Solomko <pere@pere.org.ua>

Michael Bochkaryov <misha@rattler.kiev.ua>


and that's the whole page, bestie β€” written by the legends above, and this copy is running under perl v5.36.0 from 2022-11-20 πŸ’– go forth and encode responsibly, mwah πŸ’–

πŸ“¦ where this page comes from