Core Function Chomp
From Sputnik Wiki
Chomp( <variable>, <delim> )
Contents |
Description
Removes trailing newlines and returns the number of characters removed.
Parameters
variable
Can be any variable including numbers, strings, arrays.
Note - If it finds an ARRAY it will do the chomp() on every element in the array (but not the keys).
It will chomp elements that are numeric, string or arrays it will not mess with objects etc.
delim
Optional; Provide a string that each character will be considered a newline delimiter.
Default: "\n"
Return Value
The character that was removed.
Remarks
This modifies the string in place.
This function only counts \n as a valid newline however you may provide it with a string you would like it to consider newlines.
Example
Remove all newlines from end of a string
$cat = "UberFoX\n\n\n\n\n\n"; $rem = chomp($cat); print "$rem = '$cat'\n";
Remove all characters we define as newlines from end of a string
$cat = "UberFoX\n---\r"; $rem = chomp($cat, "-\r\n"); print "$rem = '$cat'\n";