How to split a string in nxc

95 Views Asked by At

I've been trying to convert a python project to nxc using the IDE: Brixc Command Center, so that it'll read a text file and split down the information into components where it can process it. The main road block for me is the split string method which I cannot find/figure out.

in python it would be easy like Data1 = RawData.split("\n") where it would split it into a array and where I can sort through it like this: Data1[nth position in array][character in nth position in selected value in array]

I tried doing repeating the same method in nxc but it doesn't work

1: #import "RawData.txt" Data0
2: string Data1[];
3: "task main(){
4:     Data1 = Data0.split("\n");
5:     if(Data1[1][0]=="a"){
6:         TextOut(10,10,"its an a!");
7:         }else{
8:         TextOut(10,10,Data1[1][0]);
9:         }
10:    Wait(5000);
11:}
12:

the output should be the display of the first character of the second line in this case. surprisingly not, it doesn't work. and it spits out a few errors (I'm new to nxc after all).

line 3: Error: Datatypes are not compatible 
line 3: Error: ';' expected
line 3: Error: Unmatched close parenthesis
line 4: Error: Unmatched close parenthesis
1

There are 1 best solutions below

2
On

Just change the "a" to 'a'.

1: #import "RawData.txt" Data0
2: string Data1[];
3: task main(){
4:     Data1 = Data0.split("\n");
5:     if(Data1[1][0]=='a'){
6:         TextOut(10,10,"its an a!");
7:         }else{
8:         TextOut(10,10,Data1[1][0]);
9:         }
10:    Wait(5000);
11:}
12:

" denotes a string (which is an array of characters) where as ' denotes a single character.