Jump to content

function which returns union of two strings

- - - - -

  • Please log in to reply
4 replies to this topic

#1
zemzela

zemzela

    Newbie

  • Members
  • PipPip
  • 29 posts
I need to write the function which return union of two strings, but I must not use finite functions....


example

public string union(string A, string B)
{
code


}

If you know how to write this please help me....

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Start with a few examples of inputs and desired output. "union of two strings" could mean several different things.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
zemzela

zemzela

    Newbie

  • Members
  • PipPip
  • 29 posts
I solve my last problem, but there is another one.... please look through my problem. that could be c++ or c#.

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

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Shift both strings to lowercase, for starters.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
logicPwn

logicPwn

    Learning Programmer

  • Members
  • PipPipPip
  • 90 posts
        private string compareAndCombine(string first, string second)

        {

            // Convert to chars

            char[] f_chars = first.ToLower().ToCharArray();

            char[] s_chars = second.ToLower().ToCharArray();

            //

            string non_double_chars = "";

            foreach (char c in f_chars)

            {

                if (non_double_chars.IndexOf(c) == -1)

                {

                    non_double_chars += c.ToString();

                }

            }

            foreach (char c in s_chars)

            {

                if (non_double_chars.IndexOf(c) == -1)

                {

                    non_double_chars += c.ToString();

                }

            }

            // Return

            return non_double_chars;

        }

Tested and working, organization of the string is another thing.

Edited by logicPwn, 12 February 2012 - 07:20 PM.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users