#!/usr/bin/env python3
###################################################################################
# Python string functions
# All string functions must be re-assigned
###################################################################################
print("Content-Type: text/html \n")     #http header with newline char (required for the web)

print('<pre>')                          #to produce better display on the web 

str1 = "hello world, this is Python"
str2 = "Multi-line \
        string"
str3 = """Multi-line
          string"""
                  
str1.capitalize()                        #not re-assigned (no change)
print(str1)
print(str2)
print(str3)

str2 = str1.capitalize()                                         #must be assigned to same string or another string
print('capitalize first letter', str2)

print('length of the string...', len(str1) )
print('center the string......', str1.center(50) )               #view page source to see centering effect
print('left adjust............', str1.ljust(50) )                #view page source to see left adjust effect
print('right adjust...........', str1.rjust(50) )                #view page source to see right adjust effect
print('how many "h"...........', str1.count('h') )
print('does string end "on"?..', str1.endswith('on') )
print('find "this"............', str1.find('this') )
print('find "that" from 5-20..', str1.find('that',5,20) )
print('take a substring 0-10..', str1[0:11] )                    #for substring, use array notation
print('convert to lower case..', str1.lower() )
print('convert to upper case..', str1.upper() )
print('strip lead/end spaces..', str1.strip() )                  #there is also lstrip() and rstrip()
print('replace this with that ', str1.replace('this','that') )
print('replace "h" with "H"...', str1.replace('h','H') )
print('replace 1 occur of "h" ', str1.replace('h','H',1) )       #replace 1 occurrence only
print('split a string into list', str1.split() )                 #split the string on whitespace and return array 
print('split using a comma "," ', str1.split(',') )              #split on commas
chars = list(str1)                                               #split the string and return list of every char
print('split str1 on every char ', chars )
delimiter = '-'
string = delimiter.join(chars)
print('join list into a string ', string )                       
print("Hello \n World".splitlines() )                          #splits a line on \n, \r or \r\n
print("Hello \r World".splitlines() )
print("Hello \r\n World".splitlines() )