python">class offer_book:
def replaceBlank( p_str, rpl_str ):
blank = ' '
numOfBlank = 0
originalLen = len( p_str )
for char in p_str:
if char == blank:
numOfBlank += 1
originalIndex = originalLen - 1
newLen = originalLen + numOfBlank * ( len( rpl_str ) - len( blank ) )
newIndex = newLen - 1
newStr = [ blank ] * newLen
while originalIndex >= 0:
if p_str[ originalIndex ] == blank:
newStr[ newIndex ] = '0'
newIndex -= 1
newStr[ newIndex ] = '2'
newIndex -= 1
newStr[ newIndex ] = '%'
newIndex -= 1
else:
newStr[ newIndex ] = p_str[ originalIndex ]
newIndex -= 1
originalIndex -= 1
return str( newStr )
newStr = offer_book.replaceBlank( ' we are happy! ', '%20' )
print( newStr )
标签:python