Search This Blog

Saturday, January 18, 2014

Write a method to replace all spaces in a string with ‘%20’

################## Start of the Program

#!/usr/bin/python

import sys

given_str=raw_input("Please enter your string: ")

def replace_space():
    c_list=[]
    len_iter=len(given_str)
    i=0
    while len_iter>0:
        if given_str[i] == ' ':
            c_list.append("%20")
        else:
            c_list.append(given_str[i])
        i=i+1
        len_iter=len_iter - 1   
    #print "".join(c_list)
    len_iter1=len(c_list)
    j=0
    while len_iter1>0:
        sys.stdout.write(c_list[j])
        j=j + 1
        len_iter1=len_iter1 - 1
    print " "

if __name__=="__main__":
    replace_space()

################## End pf the Program

No comments:

My Profile

My photo
can be reached at 09916017317