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

  • SEARCH
  • Home
  • 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 967677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:21:28+00:00 2026-05-16T02:21:28+00:00

I have an application that uses managed System::String in the UI elements, but then

  • 0

I have an application that uses managed System::String in the UI elements, but then refers to un-managed (read: legacy) code for the more complex computation.

Additionally, there is not a consistent encoding for the strings – managed strings can be either regular "strings" or Unicode L"strings" and un-managed strings come in all of char *, wchar_t *, std::string, std::wstring varieties.

What is the best way to compare the various flavors of strings? I’m hoping that I can do this without having to implement half a dozen comparison methods like

int compare(System::String ^ s1, char * s2);
int compare(System::String ^ s1, wchar_t * s2);
int compare(System::String ^ s1, std::string s2);
int compare(System::String ^ s1, std::wstring s2);
int compare(char * s1, System::String ^ s2);
int compare(wchar_t * s1, System::String ^ s2);
...

The primary purpose will be equality comparisons, so if those are significantly easier to do, then I would like to see those answers as well.

  • 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-16T02:21:29+00:00Added an answer on May 16, 2026 at 2:21 am

    Here’s an excellent MSDN article covering this topic in both directions:

    http://msdn.microsoft.com/en-us/library/42zy2z41.aspx

    And here’s the Marshal class:

    http://msdn.microsoft.com/en-us/library/atxe881w.aspx

    With this, I would suggest defining various managed code methods that take the different types of native strings, converts them into a managed string, then compares them.

    Unfortunately, I see no way to get around permutating the different native string types. They are literally different data types, even though they both represent what we call a string. And if it messes up the conversion, you can get into some dangerous territory.

    Also, I would drop std::string out of the running, since you can easily call c_str() to get a const char * out. Same for std::wstring and wchar_t.

    Here’s an example of one:

    using namespace System::Runtime::InteropServices;
    
    public static int NativeCompare(System::String ^ s1, char * s2)
    {
        System::String ms2 = Marshal::PtrToStringAnsi((IntPtr)s2);
        return s1.CompareTo(ms2);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 492k
  • Answers 492k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Call requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS) on your Activity. May 16, 2026 at 10:23 am
  • Editorial Team
    Editorial Team added an answer (Eclipse Galileo 3.5) I didn't find any obvious way to… May 16, 2026 at 10:23 am
  • Editorial Team
    Editorial Team added an answer After a lot of research, I found out that this… May 16, 2026 at 10:23 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have an application that uses plugins that are managed via an interface I
I have an application that uses an external jar. I used eclipse and it
I have a C# application that uses several web services which were added to
I have an application (exe) that uses some strongly named dll's. If I understand
I'm working on an ASP.NET application that uses VB. I'm using a SQLReader/SQLCommand/SQLConnection within
Our product contains a task-manager system that allows applications to run code in a
I am working on an application that uses Oracle's built in authentication mechanisms to
I have an application that manages documents called Notes. Like a blog, Notes can
I am building an AJAX application that uses both HTTP Content and HTTP Header
I am writing an application that uses UIImagePickerController to take multiple pictures with 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.