- Home /
String manipulation (splitting, concatenation, etc.)
What I'm trying to do is take a 2D array of 1-char strings and merge it all into a single one, with each 'row' being a line worth (seperated by backslash-n).
The array is constructed as such: (called as 10, 40, '#')
function Initialize (Width:int, Height:int, defChar:String) {
var W: int = Width;
var H: int = Height;
var map = new String[W, H];
for (var x = 0; x < W; x++) {
for (var y = 0; y < H; y++) {
map[x, y] = defChar;
}
}
return map;
}
And concatenated (well, unsuccessfully so) as this:
function convertMapToGui (map:String[,]) {
var mapGuiString: String;
Debug.Log(map.Length);
for (var x = 0; x < 10; x++) {
for (var y = 0; y < 40; y++) {
mapGuiString += (map[x,y].ToString);
}
mapGuiString += ('\n');
}
return mapGuiString;
}
What I want is a 10x40 grid of #s. What I'm getting is a 10x40 grid of... "CompilerGenerated.__NewlineTest_convertMapToGui$callable0$30_43"
So what am I doing wrong here? And for that matter, are there any tutorials or useful pages you guys know off-hand for learning to work with strings and such in unity? Say, for an RPG-style dialogue system? I tried looking in the store for something to learn off of, but it's not showing me anything free.
Your answer
![](https://koobas.hobune.stream/wayback/20220613110640im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Check if Item is in array list C Sharp 1 Answer
writing multiple strings to a string array in a (non componement) public class 0 Answers
How to take the text from a rich text input field and save each line into an array 1 Answer
How do I print each element of a string array separately to a UI text box 2 Answers