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

Programming and modelling in uml, Introduction Currently, Omega has 178...

Introduction Currently, Omega has 178 stores UK wide. Most cities and large towns within the UK are catered for by Omega. Omega began in 1960's selling various makes of telep

Write a program for random number generator, * Comments in your code are re...

* Comments in your code are required * Main Program Operation:  # Your program should first prompt the user for an integer to seed the random number Generator. "Enter an seed

Explain the while statement - computer programming, Explain the While State...

Explain the While Statement - Computer Programming? A 'while statement' is an entry controlled loop statement. When the expression is calculated and the condition is not satisf

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

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

Simulation algorithm, Please remember to read and follow all of the assignm...

Please remember to read and follow all of the assignment guidelines. This assignment will expand upon the simulation algorithm given in class to produce a program which may be u

Program compares interest rates, 'This program compares interest rates betw...

'This program compares interest rates between two banks and determines the best bank 'Eric Weber, Adam Litchfield, Eric Romero, Sarah, Alex, Amy '10/5/12 'Lab #4 Problem 42 'CSC

Differences between user and kernel level threads, Question : (a) Many ...

Question : (a) Many systems provide support for both user threads and kernel threads, resulting in different multithreading models. What are the two differences between user

Program to translate a sentence , a) Write a program i_language(Sentence,N...

a) Write a program i_language(Sentence,NewSentence) that translates a sentence to the i-language. In this language all vowels are changed to i and all other characters are kep

develop a web page via href attribute, 1.  Develop a Web page via href att...

1.  Develop a Web page via href attribute of anchor tag and the attribute: vlink, alink, etc. 2.  Develop a Web page, in which when the user clicks on the link it will go to the

Lmc, Plan, design and dry run a program for the Little Man Computer (LMC) t...

Plan, design and dry run a program for the Little Man Computer (LMC) that produces the same result using a fixed number of 10 iterations.

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