Avatar of gpinfotech
gpinfotechFlag for India

asked on 

String difference in c# .net

Hi,

I have two strings like string1="1,2,3,4,5,6";    and string2="4,5,6";  i need to find the difference of strings and, i want store it in another string i.e the difference is "1,2,3".


Please help me.  
C#

Avatar of undefined
Last Comment
gpinfotech
ASKER CERTIFIED SOLUTION
Avatar of mayank_joshi
mayank_joshi
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of mayank_joshi
mayank_joshi
Flag of India image

here string3 is the required string.
Avatar of Kalpesh Chhatrala
try this function

        public static string ReturnDiff(string firstString, string scndString)
        {
            StringBuilder newStb = new StringBuilder();
            if (firstString != null && scndString != null)
            {
                for(int i=0;i<firstString.Length;i++)
                {
                    if (!scndString.Contains(firstString[i]))
                        newStb.Append(firstString[i]);
                }
            }
            return newStb.ToString();
        }

Open in new window

Avatar of gpinfotech
gpinfotech
Flag of India image

ASKER

Thank you
C#
C#

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).

98K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo