normal 0 false false false en-us x-none


W.A.S.S to perform following string operations using menu:

                          i.    Compare two strings.

                        ii.    Join two strings.

                       iii.    Find the length of a given string.

                       iv.    Occurrence of character and words.

                        v.    Reverse the string.

 

Program

 

#W.A.S.S. to perform string operation: compare, concate, find, occurance, reverse

 

echo "1) Compare two strings."

echo "2) Join two strings."

echo "3) Find the length of a given string."

echo "4) Occurence of character."

echo "5) Occurrence of words."

echo "6) Reverse the string."

 

echo -e "Enter the choice.: \c"

read c

 

case $c in

1)       echo -e "Enter string1:\c"

read str1

echo -e "Enter stingr2: \c"

read str2

if test $str1 = $str2

then

            echo "Entered strings are same."

else

echo "Entered string are not same."

fi

;;

 

2)       echo -e "Enter string 1: \c"

read str1

echo -e "Enter string 2: \c"

read str2

str3=`echo "$str1$str2"`

echo -e "Joint string is: \c"

echo "$str3"

;;

 

 

3)        echo -e "Enter the string: \c"

read str

echo -e "Length of the string is: \c"

echo "$str" | wc -c

;;

 

4)        echo -e "Enter the string: \c"

read str

echo -e "Enter the  character to count the occurance: \c"

read ch

len=`echo "$str" | wc -c`

len=`expr $len - 1`

occ=0

while test $len -gt 0

do

tc=`echo "$str" | cut -c$len`

if test $tc = $ch

then

occ=`expr $occ + 1`

fi

len=`expr $len - 1`

done

echo "No.of occurence : $occ"

;;

 

5)       echo -e "Enter the string: \c"

read str

echo -e  "Enter the  word to count the occurance: \c"

read cw

occ=0

for w in `echo "$str"`

do

if test $cw = $w

then

occ=`expr $occ + 1`

fi

done

echo "No.of occurence : $occ"

;;

 

6)        echo -e "Enter the string: \c"

read str

len=`echo $str | wc -c`

len=`expr $len - 1`

result=""

while test $len -gt 0

do

temp=`echo $str | cut -c $len`

len=`expr $len - 1`

result=`echo $result$temp`

done

echo "Reverse string is: $result"

;;

esac

 

Output

1) Compare two strings.

2) Join two strings.

3) Find the length of a given string.

4) Occurence of character.

5) Occurrence of words.

6) Reverse the string.

 

Enter the choice.: 1

Enter string1:mca

Enter stingr2: mca

Entered strings are same.

 

Enter the choice.: 2

Enter string 1: SVIT

Enter string 2: MCA

Joint string is: SVITMCA

 

Enter the choice.: 3

Enter the string: SVIT

Length of the string is:       4

 

Enter the choice.: 4

Enter the string: SEMESTER

Enter the  character to count the occurance: E

No.of occurence : 3

 

Enter the choice.: 5

Enter the string: welcome to svit svit svit

Enter the  word to count the occurance: svit

No.of occurence : 3

 

Enter the choice.: 6

Enter the string: SVIT

Reverse string is: TIVS

Request for Solution File

Ask an Expert for Answer!!
Application Programming: normal 0 false false false en-us x-none
Reference No:- TGS0161500

Expected delivery within 24 Hours