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

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

Posted Date: 9/26/2012 6:30:46 AM | Location : United States







Related Discussions:- Compare 2 strings,join 2 strings,length of a given string, Assignment Help, Ask Question on Compare 2 strings,join 2 strings,length of a given string, Get Answer, Expert's Help, Compare 2 strings,join 2 strings,length of a given string Discussions

Write discussion on Compare 2 strings,join 2 strings,length of a given string
Your posts are moderated
Related Questions
Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4

I have to create a bank atm machine using MS-DOS. I am struggling to create LIST ALL ACCOUNTS ROLL-BACK TRANSACTIONS ACCESS AN ACCOUNT

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

Really urgent help needed with Javascript. I have this website: I">https://www.theppcpresents.com/globe13/#/home I need to remove the video on the slider so that it only sho

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

What is .NET TECHNOLOGY? .NET technological innovation was presented by Enthusiasm, to get the industry from the SUN's Coffee. Few in the past, Enthusiasm had only VC++ and VB

Extensive programming platform .NET It is a new, simple, and comprehensive selection foundation. It is not a selection terminology, but it can handle several selection dialects.

a program that enter an alphabet from the user and compare it is vowel or not?

Expertsmind brings you unique solution in java assignments Swing Move is the primary Java GUI gadget tool set. It is part of Oracle's Java Groundwork Sessions (JFC) - an A