Apache Pig Tutorial on Apache Pig String Functions

we have the following string functions in apache pig.

s.n. functions & description
1 endswith(string, testagainst)

to verify whether a given string ends with a particular substring.

2 startswith(string, substring)

accepts two string parameters and verifies whether the first string starts with the second.

3 substring(string, startindex, stopindex)

returns a substring from a given string.

4 equalsignorecase(string1, string2)

to compare two stings ignoring the case.

5 indexof(string, ‘character’, startindex)

returns the first occurrence of a character in a string, searching forward from a start index.

6 last_index_of(expression)

returns the index of the last occurrence of a character in a string, searching backward from a start index.

7 lcfirst(expression)

converts the first character in a string to lower case.

8 ucfirst(expression)

returns a string with the first character converted to upper case.

9 upper(expression)

upper(expression) returns a string converted to upper case.

10 lower(expression)

converts all characters in a string to lower case.

11 replace(string, ‘oldchar’, ‘newchar’);

to replace existing characters in a string with new characters.

12 strsplit(string, regex, limit)

to split a string around matches of a given regular expression.

13 strsplittobag(string, regex, limit)

similar to the strsplit() function, it splits the string by given delimiter and returns the result in a bag.

14 trim(expression)

returns a copy of a string with leading and trailing whitespaces removed.

15 ltrim(expression)

returns a copy of a string with leading whitespaces removed.

16 rtrim(expression)

returns a copy of a string with trailing whitespaces removed.