I had code in C++ which works really. I need to find alternative solution for this kind of solution... Could some help me how to change the code ...

#include <string>
	#include <iostream>
	using namespace std;
	int main(){
	string s1="abv"; //Set up string 1
	string s2="vxz"; //Set up string 2
	string s3; //Setup string 3
	 
	cout<<"First string: "<<s1<<endl;
	cout<<"Second string: "<<s2<<endl;
	s3=s1; //Copy string 1 into string 3
	for(int i=0;i<s2.size();i++){ //Loop through s2
	char c=s2[i]; //Grab current character from s2
	bool is_c_in_s3=false;
	for(int j=0;j<s3.size();j++){ //Loop though s3
	
    if (c == s3[j]) {
        is_c_in_s3=true;
        break;
    }
	}
	if(!is_c_in_s3){
		
	s3=s3+c; //Add to String 3
	}
	}
	cout<<"Final string: "<<s3<<endl;
	}

Not sure what you mean. Like this?

#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

string strUnion(string &s1,string &s2){
   string::iterator it;
   string s3(s1);
   size_t pos;
   for(it=s2.begin();it!=s2.end();it++){ //Loop through s2
       if ( (pos = s1.find(*it)) == string::npos){
           s3.append(1,*it);
       }
   }
   sort(s3.begin(),s3.end());
   return s3;
}
int main(){
   string s1="abc"; //Set up string 1
   string s2="aefg"; //Set up string 2
   cout<<"First string: "<<s1<<endl;
   cout<<"Second string: "<<s2<<endl;
   cout<<"Final string: "<<strUnion(s1,s2)<<endl;
   return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.