Problem on writing the copied array of string on text pad

Hi Every One,

I have come up with the new issue, here i want to write the my string data to my note pad through the scripting. When i write it my last array string only displayed because of over writing.

Actually i want to copy the string from one array to other string array and then i want to write it on note pad.
Here i gave my script, if you have any solution please tell me.

using UnityEngine;
using System.Collections;
using System.IO;
using System.Text;

public class Black : MonoBehaviour { 

    public static bool temp;    
    public string[] test;
    public string[] gf;

    // Use this for initialization
    void Start () {       

        temp = false;   
    }   

    // Update is called once per frame
    void Update () {       

        if(temp)
        {      

            for(int i =0; i < test.Length; i++)
            {
                gf = new string[test.Length];              

                gf _= test*;*_

File.WriteAllLines(Application.dataPath+“/Test.txt”, gf);

} }
}

void OnMouseUpAsButton()
{
temp = !temp;

}
}

You’re declaring the array and writing the file on each iteration of the loop! Do the following instead:

void Update ()
{        
        if (temp)
        {
            gf = new string[test.Length];  
            for(int i =0; i < test.Length; i++)
                gf _= test*;*_

File.WriteAllLines(Application.dataPath+“/Test.txt”, gf);
}
}

pretty sure write all lines doesnt append (that is add to a file)
but instead overwrites.

You’d want to do something like

string MyString;

foreach (string word in MyString){
MyString += word;
}

That will be everything you might want to insert spaces between. like

MyString += " " + world;

you can thing just write the string to the file now that you’ve got it all in a string.

you can copy from one string array to another easily enough

string[] OldArray;
string[] NewArray;

OldArray = new string;
// fill old array

system.array.copy(OldArray,NewArray,OldArray.length);

code has not been error checked its just pseudo code.
mark as answered please :slight_smile: