# Using multiple strings within the path to Write to Text File [closed]

In Unity3D, How would I use something like this: path = "C:\Users\Jonathan\Documents\FileData" + fileName + ".txt"; so I can make a for loop and create several text files under desired path?

The loop looks like this currently:

named = namesAsset.text.Split ('\n');
sliced = statAsset.text.Split ('\n');
for (int i = 0; i < named.Length; i++) {
fileName = named[i].ToLower();
path = "C:\Users\Jonathan\Documents\FileData" + fileName.Substring(1) + ".txt";
File.WriteAllText(path, sliced[i]);
Debug.Log (named[i]+".txt");
}


But there is a problem: They won't accept this! It spits out the error that the name has an invalid char.

Full script:

using UnityEngine;
using UnityEditor;
using System.IO;
using System.Text;
using System;

public class SplitPage : ScriptableWizard {

public TextAsset statAsset;
public TextAsset names;

public string[] named = new string[151];
public string[] sliced = new string[151];
public string path;

public string fileName;

static void CreateWizard() {
ScriptableWizard.DisplayWizard<SplitPage>("Split Text File", "Create");
}

void OnWizardCreate() {
named = names.text.Split ('\n');
sliced = statAsset.text.Split ('\n');
for (int i = 0; i < named.Length; i++) {
fileName = named[i].ToLower();
path = "C:\Users\Jonathan\Documents\FileData" + fileName.Substring(1) + ".txt";
File.WriteAllText(path, sliced[i]);
Debug.Log (named[i]+".txt");
}

}
}


## closed as off-topic by MichaelHouse♦Sep 1 '14 at 15:09

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "Programming questions that aren't specific to game development are off-topic here, but can be asked on Stack Overflow. A good rule of thumb is to ask yourself "would a professional game developer give me a better/different/more specific answer to this question than other programmers?"" – MichaelHouse
If this question can be reworded to fit the rules in the help center, please edit the question.

• You want several files with the same path? I don't get it. – Laurent Couvidou Sep 1 '14 at 14:49
• Each one is SUPPOSED to change depending on what named[i] is at that point. – BillTrollberg Sep 1 '14 at 15:08
• This is a bit confusing. Is that first code snippet meant to be part of the second one? They almost match, but not exactly. – Anko Sep 1 '14 at 21:55
• They DO match, because that first bit was where the script goes Haywire. the 2nd is the full code. – BillTrollberg Sep 2 '14 at 1:21

It is impossible to know for certain from the given code what the issue is, but a reasonable guess is that you namesAsset string contain DOS/Windows style line endings, and therefore when you split by '\n' you leave an '\r' at the end of strings.