string s1="Ui";
string s2="uk";
How can I compare them and print result just Uik or uik. not twice Uuik. my program understand such as different values(Uu). Is there any function or something like that? thank you a lot

How about this?:

using System.Linq;

namespace DW_411760_CS_CON
{
   class Program
   {
      static void Main(string[] args)
      {
         string s1 = "Ui";
         string s2 = "uk";
         string s3 = new string((s1 + s2).ToLower().Distinct().ToArray());
      }
   }
}

Edited 4 Years Ago by thines01: correction

Is it OK if it comes back as "iku"?

Yes, it is ok. the problem is how to display just one letter "u" or "U"? thank for your time

How about this?:

using System.Linq;

namespace DW_411760_CS_CON
{
   class Program
   {
      static void Main(string[] args)
      {
         string s1 = "Ui";
         string s2 = "uk";
         string s3 = new string((s1 + s2).ToLower().Distinct().ToArray());
      }
   }
}

yes it works this in c#, thank you. but have you an idea how can I do this in c++???

I would do it sort of like this:

#pragma once
using namespace System;
using namespace System::Collections::Generic;
using namespace System::Linq;

namespace DW_411760_CPP_LIB {
   public ref class CProgram
   {
   public:
      static String^ MergeString(String^ s1, String^ s2)
      {
         String^ s3 = gcnew String(
            Enumerable::ToArray(Enumerable::Distinct((s1+s2)->ToLower())));
         return s3;
      }
   };
}

...and then you can call it from the C# program:

using System.Linq;
using DW_411760_CPP_LIB;

namespace DW_411760_CS_CON
{
   class Program
   {
      static void Main(string[] args)
      {
         string s1 = "Ui";
         string s2 = "uk";
         string s3 = new string((s1 + s2).ToLower().Distinct().ToArray());
         string s4 = CProgram.MergeString(s1, s2);
      }
   }
}
Comments
Continuous efforts!

In order to make that work, you will need to change the C# project to the highest dot net level and add a new C++ project as a Class Library.
You will then need to add a refrence from inside the C# project to the C++ project, add the necessary code and compile.

Yes, it is ok. the problem is how to display just one letter "u" or "U"? thank for your time

Interesting that you are answering a quoted phrase that doesn't exist now and his post doesn't show as edited.

Since his replaced text fully answers your question, you should either mark this thread as solved or explain why his answer doesn't solve the solution.

His solution is case insensitive, the way you stated the problem makes it look like you really wanted that, not one that is case sensitive which is the default behaviour. If you do want case sensitive, remove the .ToLower() function.

I did edit that post.

I DO assume this thread should be marked solved unless the OP is not into my flavor of C++.

If not, the concept is the same: neutralize the case and remnove duplicates.

I DO assume this thread should be marked solved unless the OP is not into my flavor of C++.

My comment about "solved" was directed at kikiritce who is the only one who can mark this thread Solved. It is still marked UnSolved.

This article has been dead for over six months. Start a new discussion instead.