Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6076841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:39:14+00:00 2026-05-23T10:39:14+00:00

I just want to know the difference between CompareStr and = for comparing strings

  • 0

I just want to know the difference between CompareStr and = for comparing strings in Delphi. Both yield the same result.

if(str2[i] = str1[i]) then
  ShowMessage('Palindrome')

if(CompareStr(str2[i], str1[i]) = 0) then
  ShowMessage('Palindrome')

Both show message Palindrome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:39:14+00:00Added an answer on May 23, 2026 at 10:39 am

    Use CompareStr not when you just want to see whether two strings are equal, but when you want to know how one string compares relative to another. It will return a value less than 0 if the first argument appears first, asciibetically, and it will return a value greater than zero if the first argument belongs after the second.

    Without CompareStr, you might have code like this:

    if str1[i] = str2[i] then begin
      // They're equal
    end else if str1[i] < str2[i] then begin
      // str1 comes first
    end else begin
      // str2 comes first
    end;
    

    That compares str1 and str2 twice. With CompareStr, you can cut out one of the string comparisons and replace it with a cheaper integer comparison:

    x := CompareStr(str1[i], str2[i]);
    if x = 0 then begin
      // They're equal
    end else if x < 0 then begin
      // str1 comes first
    end else begin
      // str2 comes first
    end;
    

    As Gerry’s answer explains, the function is particularly useful in sorting functions, especially since it has the same interface as other comparison functions like CompareText and AnsiCompareStr. The sorting function is a template method, and each of the functions serves as a comparison strategy.

    If all you want to do is test for equality, use the = operator — it’s easier to read. Use CompareStr when you need the extra functionality it provides.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just want to know what is the difference between sending parameter with ajax(post/get)
I just want to know what the difference between all the conditional statements in
I just want to know what is the difference between C library and standard
just i want to know What is the actual difference between MVC and MVC
i just want to know what is the difference between rtsp and rtmp protocol
I just want to know the actual difference between android dev phone, android nomral
I just want to know the difference between: sort < output and sort output
i just want to know the difference between using ACL and spring role-based authorization
i just want to know the difference between using @ManyToMany relationship wit @JoinColumn and
I don't care what the differences are. I just want to know whether the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.