954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Case sensitive

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

kikiritce
Newbie Poster
20 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

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());
      }
   }
}
thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 
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

kikiritce
Newbie Poster
20 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

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++???

kikiritce
Newbie Poster
20 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

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);
      }
   }
}
thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 

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.

thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 

Did you try it?

thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 
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.

kplcjl
Junior Poster
149 posts since Sep 2009
Reputation Points: 16
Solved Threads: 12
 

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.

thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 
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.

kplcjl
Junior Poster
149 posts since Sep 2009
Reputation Points: 16
Solved Threads: 12
 

Oh, I understand...

thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: