sample_string = "  this sample string will be used as a SAMPLE string "

# Slicing work the same way as in arrays
sample_string[:13]

# Splits string according to delimiter and returns list of substrings;
# space is the default delimiter
# split into at most n substrings, where n is optional
sample_string.split(' ', 4)

# Splits string at all (or num) NEWLINEs and returns a list of each line with NEWLINEs removed.
sample_string.splitlines()

# Replaces all occurrences of the in the string of first argument with
# the second one at most n occurrences
sample_string.replace(' ', '$') 

# Removes all leading and trailing repetition of the provided pattern in string
print "strip:", sample_string.strip('s')
# Removes all leading repetition of the provided pattern in string
print "rstrip:", sample_string.rstrip()
# Removes all  trailing repetition of the provided pattern in string
print "lstrip:", sample_string.lstrip()

# Return the string of the object parameter
print "str:", str('123')
# Return the Unicode string of the object parameter
print "unicode", unicode('123')
# Given a string of length one, return an integer representing the Unicode code
print "ord:", ord('a')
# Return a string of one character whose ASCII code is the integer parameter
print "chr", chr(97)
# Return the Unicode string of one character whose Unicode code is the integer i
print "unichr:", unichr(97)

# Converts all uppercase/lowercase letters to lowercase/uppercase
print "   lower:", sample_string.lower()
print "   upper:", sample_string.upper()
# Inverts case for all letters
print "swapcase:", sample_string.swapcase()

"""
Explanation: String Manipulation
The following snippet shows the most important built in functions that you should be familiar.
End of explanation
"""


# Capitalizes first letter of string
sample_string.capitalize()

# Returns a string center for the width provided.
sample_string.center(80, ' ')

# Counts how many times str occurs in string or substring if setting min and max indices are set
# IT´S CASE SENSITIVE
print sample_string.count('string') 
print sample_string.count('string', 0, 30)

# Test if string or a substring of string ends with provided string
print sample_string.endswith('SAMPLE') 
print sample_string.endswith('SAMPLE', 0, len(sample_string)-8)

# Determine if provided string occurs in string or in a substring
# Return index of first appearance or -1 if not found
print "find:", sample_string.find('string') #(beg=0 end=len(string))
# Performs search starting from the right
print "rfind:", sample_string.rfind('string') #(beg=0 end=len(string))

# Determine if provided string occurs in string or in a substring
# Return index of first appearance or raised an exception if not found
print "index:", sample_string.index('will be') #(beg=0, end=len(string))
# Performs index search starting from the right
print "rindex:", sample_string.rindex('will be') #(beg=0, end=len(string))

# Returns true if string has at least 1 character and all characters
# are alphanumeric and false otherwise.
print "isalnum()", sample_string.isalnum()
# Returns true if string has at least 1 character and all characters
# are alphabetic and false otherwise.
print "isalpha()", sample_string.isalpha()
# Returns true if string contains only digits and false otherwise.
print "isdigit()", sample_string.isdigit()
# Returns true if string has at least 1 cased character and all cased 
# characters are in lowercase and false otherwise.
print "islower()", sample_string.islower()
# Returns true if string contains only whitespace characters and 
# false otherwise.
print "isspace()", sample_string.isspace()
# Returns true if string is properly "titlecased" and false otherwise.
sample_string.istitle()
# Returns true if string has at least one cased character and all 
# cased characters are in uppercase and false otherwise.
print "isupper()", sample_string.isupper()

# Returns a string with the original string left-justified 
print "ljust:", sample_string.ljust(80,' ')
# Returns a string with the original string right-justified to a total of width columns
print "rjust:", sample_string.rjust(80,' ')

"""
Explanation: Secondary methods
Although important, you will probably use them less frequently.
End of explanation
"""


