2 Replies - 407 Views - Last Post: 14 July 2017 - 06:53 PM

#1 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 242
  • Joined: 29-October 16

Using WriteAllText(): "\n" Newline Escape Sequence Does Nothin

Posted 11 July 2017 - 12:51 PM

Hey all,
I'm extremely frustrated here and just about @ my wits end with this one. I cannot figure out what I'm doing wrong here except that last time when I was writing to a file I was using the marshal strings library so maybe this has something to do with that. Anywhoo... here's what I'm working with:

		//Move Button
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
	{
	//Declare Strings
		
		String^ destinationHost;
		destinationHost = textBox5->Text;

		String^ sourceHost;
		sourceHost = textBox2->Text;

		String^ sourceUserName;
		sourceUserName = textBox3->Text;

		String^ destinationPath;
		destinationPath = textBox6->Text;

		String^ destinationUser = textBox4->Text;

		String^ sourceScript;

		String^ destinationScript;

		String^ fullScript;
		if (radioButton2->Checked == true)
		{
			sourceScript = "Copy-Item " + "\\\\" + sourceHost + "\\" + "c$" + "\\users\\" + sourceUserName + "\\" + " -Recurse ";
		}
//		if (radioButton1->Checked == true)
//		{
//			sourceScript = "Copy-Item " + "\\\\" 
//		}
//
		if (radioButton3->Checked == true)	
		{
			destinationScript = "\"" + "\\\\" + destinationHost + "\\" + "c$" + "\\users\\" + destinationUser + "\\Desktop\\" + sourceUserName + " Files\\" + "\"";
		}
		String^ setExecute;
		setExecute = "Set-ExecutionPolicy Unrestricted" + "\n";

		fullScript = sourceScript + destinationScript;

		String^ execPlusFull;

		execPlusFull = setExecute + fullScript;

		System::IO::File::WriteAllText("userDataTransfer.ps1", execPlusFull);
	}




So everytime that I try and add "\n" into my Strings^ it's now not working... :(/>/>/>/>

I have no idea why.. last time I used this escape sequence a hundred times with the marshal strings and ofstream method of writing to file. Basically I'm trying to write another .ps1 file but for some reason when I write to the file and go into it there's no space[EDIT: NO NEW LINE, sorry I said space but mean no new line].

So when I click this button it's not a usable script because the set-executionpolicy unrestricted is mashed in with the copy-item code. Can anyone explain to me why the newline escape sequence isn't working, judging by that code? The whole thing compiles fine it's just as if there's no escape sequence. I've tried putting the "\n" all over the place in those String^s but no matter where it put it ... they never work. Wassupwidat? :crazy:/>/>/>/>

This post has been edited by hexagod: 12 July 2017 - 09:57 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Using WriteAllText(): "\n" Newline Escape Sequence Does Nothin

#2 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 242
  • Joined: 29-October 16

Re: Using WriteAllText(): "\n" Newline Escape Sequence Does Nothin

Posted 12 July 2017 - 07:49 AM

SOLUTION:

For managed String^ s have to use \r\n
Was This Post Helpful? 0
  • +
  • -

#3 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5921
  • View blog
  • Posts: 20,243
  • Joined: 05-May 12

Re: Using WriteAllText(): "\n" Newline Escape Sequence Does Nothin

Posted 14 July 2017 - 06:53 PM

Only on Windows. On Linux, '\n' is all you need.

For platform independent code, you'll want to use Environment::Newline. It will resolve the right thing for the current environment.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1