answersLogoWhite

0

In most programming languages you will be relying on pre-existing library functions for all your string comparison needs.

The algorithm is:

  • Consider both strings as arrays of characters (depending on the language, they will either have a specified maximum length, eg in Pascal or a terminating symbol - usually a zero - eg in C and C++)
  • Iterator n represents the position in the character string, with its' initial value representing the first index in the array. If the language permits it, you can use pointer arithmetic instead.
  • For each character in a string:
  1. Take the n-th character from string 1
  2. Take the n-th character from string 2
  3. Compare both characters (the exact comparison method may vary)
  4. If not equal, return false
  5. Increase n by 1
  • If reached end of string, return true

Here is an example function in C (returning a 1 if the strings are identical, 0 if not). This implementation forgoes use of an iterator in favor of pointer arithmetic and comparison in favor of XORing the characters with each other (a XOR of identical values returns a zero):

int string_compare(char* a, char* b)

{

while (*a)

{

if (*a++^*b++) return 0;

}

return 1;

}

User Avatar

Wiki User

12y ago

What else can I help you with?

Continue Learning about Computer Science

What are the advantages of a diaphragm spring clutch?

Diaphragm clutch is smaller specially on size compare to other spring clutch. It also transmits much more torque as diaphragm exerts more force as compare to other strings.


Can you write a grammar for the language consisting of strings?

Yes, a grammar for a language consisting of strings can be written using production rules that define how strings can be formed. Each rule specifies how different parts of a string can be combined or modified. The grammar can include rules for creating basic strings, concatenating strings, repeating characters, and more complex patterns.


Why are strings immutable in programming languages?

Strings are immutable in programming languages because it helps ensure data integrity and security. Immutable strings cannot be changed once they are created, which prevents accidental or malicious alterations to the data they represent. This makes strings more reliable and easier to work with in complex software systems.


How does every language reduce to its complement?

Every language can be reduced to its complement by taking the set of all possible strings and removing the strings that are in the original language. This process results in the complement language, which consists of all strings not in the original language.


What is the total number of all binary strings that do not contain the substring "010"?

The total number of all binary strings that do not contain the substring "010" is 2n1, where n is the length of the binary string.

Related Questions

How do you campaire Strings in java?

String class in Java has an 'equals' method that can be used to compare strings.


Which operator is used to compare strings in Perl?

eq


Does C allows you to use equality operators to compare strings?

Yes, it does.


How do electric bass strings compare to upright bass strings?

Well, for one, string bass strings are a lot longer than electric bass strings. I wouldn't recommend putting string bass strings on an electric bass and vice versa.


Write a script that accepts two strings from the user and compare two strings in web technology?

how to compare two strings that take input from the user and compare it. For example: i give first string as "THE" and give second string as "HTE" then return "match" if i give first as"THE" nd second string as "EHI" then return "NOtMatch" witout using STRCMP ... please help me


How does the size of a viola compare to that of a violin?

The viola is larger than the violin, with a longer body and longer strings.


'c' code to compare two strings using strcmp function?

char one [] = "A string" ;char two [] = "Different String" ;if (strcmp (one, two) == 0){puts ("The two strings are identical") ;}else{puts ("The two strings are different") ;}


How do you compare a string puppet and a finger puppet?

Well, a finger puppet is a cloth or felt puppet put on your finger during plays. A string puppet is a puppet hung by strings. When the person pulls the strings, the puppet moves. There are some other ways you could compare because of quality, efficency etcetera, but this is the basics.


What are the advantages of a diaphragm spring clutch?

Diaphragm clutch is smaller specially on size compare to other spring clutch. It also transmits much more torque as diaphragm exerts more force as compare to other strings.


What are the thinnest guitar strings available on the market and how do they compare to standard gauge strings in terms of playability and sound quality?

The thinnest guitar strings available on the market are typically referred to as "ultra-light" or "extra-light" gauge strings. These strings are easier to press down and bend, making them more playable for beginners or players with weaker fingers. However, they may sacrifice some sound quality and tone compared to standard gauge strings, which are thicker and produce a fuller, richer sound. Ultimately, the choice between thin and standard gauge strings depends on personal preference and playing style.


What is the use of strcmp function in c plus plus?

strcmp is used to compare two strings. If the return value is zero, the two strings are the same. If the return value is less than 0, then the first string is less than the second string, otherwise the first string is greater than the second string. Strings are compared lexicographically, character by character.


What is the C plus plus program for string compare?

You don't need a program to compare strings since std::string already provides support for all the comparison operators (<, <=, >, >=, == and !=). To roll your own you must first create a string class and then provide operator overloads for the comparison operators. To compare strings, start at the first character in each string and compare. So long as they remain equal, move onto the next character. The comparison ends as soon as any character differs. You need only compare these two characters to decide which string is the lesser. To perform a case insensitive comparison, copy the two characters and convert the copies to lower case (or upper case, it doesn't matter). Then compare the copies. Do this for each character as you compare them rather than converting the entire string.