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....
4 replies to this topic
#1
Posted 12 February 2012 - 07:34 AM
|
|
|
#2
Posted 12 February 2012 - 03:53 PM
Start with a few examples of inputs and desired output. "union of two strings" could mean several different things.
#3
Posted 12 February 2012 - 04:00 PM
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
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
Posted 12 February 2012 - 04:09 PM
Shift both strings to lowercase, for starters.
#5
Posted 12 February 2012 - 06:28 PM
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


Sign In
Create Account


Back to top









