Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

c++ casting char array to System::String^


ghost's Avatar
0 0

i cant find a way to do this i can cast a String^ to a char * but not the othter way! anyone help?


ghost's Avatar
0 0

i think thats because in one way you lose data, which is fine, but you cant gain data….


ghost's Avatar
0 0

your having a problem because i think you CANT do it the other way


ghost's Avatar
0 0

ok well then can someone help me with this?

I have created a small encryption programme but, to get the information from the rich text box it gets/sets it as a System::String ^ so when i encrypt each letter inside it and try to set the String ^ back to the new encrypted values it says "System::String ^ does not have a "set" method. now i understand what this means but i do not know how to get arround this.


ghost's Avatar
0 0

You'll have to be more specific with what you mean, perhaps a code snippet so I can try and re-create what you are doing.

Cheers, T-Metal


ghost's Avatar
0 0
public: static String^ Encrypt(String^ str, char *chr)
	{
		printf("Encrypt -> arg[0] = %s arg[1] = %s\n",str, chr);
		//i want to be able to get the plain text and encrypt it in this loop and return as a String ^
		for(int i = 0; i < strlen(chr); i++)
		{
			//str[i] = str[i] ^ woopdewoop;
		}
		printf("str: %s\n",str);
		return str;
	}

void btnEncrypt_Click(Object^, EventArgs^)
	{
		String^ tmp = getEncryptionInput();
		char *str = str_to_char(tmp);
		
		printf("%s\n",Encrypt(tmp, str));
		//setEncryptionOutput(str.ToString);
	}

it wont let me set a string using "="


ghost's Avatar
0 0

What the hell is str_to_char().


ghost's Avatar
0 0

oh that's just a simple function to cast my String ^ to char arrays


ghost's Avatar
0 0

What line is screwing up than exactly.. :@:angry::happy::ninja:


ghost's Avatar
0 0

none of the lines are really screwing up… i need to be able to encrypt a System::String ^ but when i am trying to "set" the string to the new encrypted value eg. String ^str, newStr; str = "hello"; stf[i] = str[i]^143;///made up stuff

thats basicly what i want to e able to do but it wont let me set the str[i] again