Compare 2 strings,join 2 strings,length of a given string, Programming Languages

Assignment Help:

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


Related Discussions:- Compare 2 strings,join 2 strings,length of a given string

Write a program that lets the user play an adventure game, Let the player (...

Let the player (denoted U in the diagram below) navigate around the board until she wins the game by finding the exit or is killed by a monster. A player begins the game with a sli

Java networking, Expertsmind brings you unique solution in java assignment...

Expertsmind brings you unique solution in java assignments Networking The term system selection represents composing applications that do across several gadgets (computers

Enter no of hours days months years contains pattern , Normal 0 ...

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4

FORTRAN, WRITE A FORTRAN PROGRAMME TO GENERATE PRIME NUMBERS BETWEEN 1 AND ...

WRITE A FORTRAN PROGRAMME TO GENERATE PRIME NUMBERS BETWEEN 1 AND 100.

Prims algorithm for minimum spanning tree, Implement the Prim's algorithm w...

Implement the Prim's algorithm with array data structure as described in slide 12 of the file 04mst.ppt. Your program should have a runtime complexity of O(n2) and should be as eff

Write a program that prints gross and net pay and taxes , Assume that a vid...

Assume that a video store employee works 50 hours. She gets paid $4.50 for the first 40 hours; she gets time-and-a half pay (1.5 times the regular pay rate) for the first five hour

Develop a mobile phone application for games, You have been asked to set up...

You have been asked to set up a project plan for developing a mobile phone application for London Olympics. Major tasks include conducting some research into different mobile ph

Fortran function for find and print out all prime number, Write a Fortran L...

Write a Fortran LOGICAL FUNCTION, called "is_prime", which determines if a given integer value is a prime number or not (A prime number is a natural number which has only two disti

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd