-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings
More file actions
executable file
·63 lines (55 loc) · 1.82 KB
/
strings
File metadata and controls
executable file
·63 lines (55 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env bash
#
# ############################################################################
# Project: xSHELL (none)
# File...: strings
# Created: Friday, 2021/05/21 - 21:09:41
# Author.: Fabiano Matos, fgm (fabiano.matoz@gmail.com)
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Last Modified: Tuesday, 2025/02/18 - 01:27:08
# Modified By..: @fbnmtz, (fabiano.matoz@gmail.com)
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Version: 0.1.5.109
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Description:
# >
# ############################################################################
# HISTORY:
#
_xLIB_STRINGS_=true
# split a string by a ginver char
# @param $1 - string to be splited
# @param $2 - split in this char (it will be removed)
# @return $array - string splited
str.split(){
local array=( $(echo "$1" | tr -s "$2" ' ') )
echo "${array[@]}"
}
# convert string to a array with each char
str.chars(){
local array=( $(echo "$1" | fold -w1 | tr -s '\n' ' ') )
echo "${array[@]}"
}
# get SIZE of a str
str.len(){ echo "${#1}"; }
str.size(){ str.len "$@"; }
# reverse a str
str.reverse(){ echo "$1" | rev; }
str.rev(){ str.reverse $1; }
# change case of a string
str.upcase(){ echo "$1" | tr a-z A-Z ; }
str.lowcase(){ echo "$1" | tr A-Z a-z ; }
# check if a string contains another string
# @param $1: string alvo da busca
# @param $2: texto a ser pesquisado na string
str.include?(){
local string=$1; reqsubstr=$2;
if [[ "${string}" =~ ${reqsubstr} ]]; then
# if [ -z "${string##*$reqsubstr*}" ]; then
# echo "true"
return 0
else
# echo "false"
return 1
fi
}