how do I find the length of a string array
in
Programming Questions
•
1 years ago
Im trying to find the length of a array of strings but cince the variable string already contains the length function, it gives me an error. Does anyone know how to find the length of a array of strings?
Here is my code:
char screentext[][] = new char[101][31];
PFont font,font30;
int x,y;
int blink;
String file;
void setup(){
size(1000,600);
font = loadFont("CourierNewPSMT-12.vlw");
font30 = loadFont("CourierNewPSMT-30.vlw");
textFont(font, 15);
file = selectInput();
}
void draw(){
fill(0,255,0);
stroke(0,255,0);
String board[] = loadStrings(file);
for(int i=board.length; i>board.length-6; i--){
text(board[i],10,290-i*10);
}
textFont(font, 15);
blink = blink+1;
x=constrain(x,0,99);
y=constrain(y,0,29);
background(0);
fill(0,255,0);
stroke(0,255,0);
for(int i=0; i<30; i++){
for(int j=0; j<100; j++){
text(screentext[j][i],j*10,i*10+310);
}
}
if(blink < 20){
stroke(0,255,0);
line(x*10,y*10+300,x*10,y*10+310);
/*
for(int i=0; i<10; i++){
for(int j=0; j<10; j++){
//x*10+i,y*10+300+j
}
}
*/
}
if(blink > 40){
blink = 0;
}
stroke(0,255,0);
line(0,300,width,300);
if(mouseX >= 10 && mouseX <= 110 && mouseY >= 10 && mouseY <= 60){
fill(0,255,0);
if(mousePressed){
stroke(0);
send();
}else{
stroke(0,255,0);
}
}else{
noFill();
stroke(0,255,0);
}
rect(10,10,100,50);
if(mouseX >= 10 && mouseX <= 110 && mouseY >= 10 && mouseY <= 60){
fill(0);
}
textFont(font30, 30);
smooth();
text("send",25,40);
noSmooth();
}
void keyPressed(){
if(keyCode != LEFT && keyCode != RIGHT && keyCode != UP && keyCode != DOWN && keyCode != SHIFT && keyCode != BACKSPACE){
screentext[x][y] = key;
}
if(keyCode == UP){
y--;
blink = 0;
}else if(keyCode == DOWN){
y++;
blink = 0;
}else if(keyCode == LEFT){
x--;
blink = 0;
}else if(keyCode == RIGHT){
x++;
blink = 0;
}else if(keyCode == BACKSPACE){
if(x>0){
x--;
}
if(y>0 && x==0){
y--;
}
screentext[x][y] = ' ';
}else if(keyCode == ENTER){
y++;
x=0;
}else if(keyCode == TAB){
x=x+3;
}else if(keyCode == SHIFT){
}else{
x++;
}
}
boolean mouseisin(int x1, int y1,int x2,int y2) {
if(mouseX > x1 && mouseX < x2 && mouseY > y1 && mouseY < y2) {
return true;
}
else {
return false;
}
}
color invert(color input) {
return color(255-red(input),255-green(input),255-blue(input));
}
void send(){
String temp_save[] = loadStrings(file);
String temp_extend[] = new String[temp_save.length() + 1];
for(i=0; i<temp_save.length+1; i++){
temp_extend[i] = temp_save[i];
}
String temp_submit;
for(int i=0; i<30; i++){
for(int j = 0; j<100; j++){
temp_submit = temp_submit + screentext[j][i];
}
}
temp_submit=trim(temp_submit);
temp_extend[temp_extend.length()] = temp_submit;
saveStrings(file, temp_extend());
}
PFont font,font30;
int x,y;
int blink;
String file;
void setup(){
size(1000,600);
font = loadFont("CourierNewPSMT-12.vlw");
font30 = loadFont("CourierNewPSMT-30.vlw");
textFont(font, 15);
file = selectInput();
}
void draw(){
fill(0,255,0);
stroke(0,255,0);
String board[] = loadStrings(file);
for(int i=board.length; i>board.length-6; i--){
text(board[i],10,290-i*10);
}
textFont(font, 15);
blink = blink+1;
x=constrain(x,0,99);
y=constrain(y,0,29);
background(0);
fill(0,255,0);
stroke(0,255,0);
for(int i=0; i<30; i++){
for(int j=0; j<100; j++){
text(screentext[j][i],j*10,i*10+310);
}
}
if(blink < 20){
stroke(0,255,0);
line(x*10,y*10+300,x*10,y*10+310);
/*
for(int i=0; i<10; i++){
for(int j=0; j<10; j++){
//x*10+i,y*10+300+j
}
}
*/
}
if(blink > 40){
blink = 0;
}
stroke(0,255,0);
line(0,300,width,300);
if(mouseX >= 10 && mouseX <= 110 && mouseY >= 10 && mouseY <= 60){
fill(0,255,0);
if(mousePressed){
stroke(0);
send();
}else{
stroke(0,255,0);
}
}else{
noFill();
stroke(0,255,0);
}
rect(10,10,100,50);
if(mouseX >= 10 && mouseX <= 110 && mouseY >= 10 && mouseY <= 60){
fill(0);
}
textFont(font30, 30);
smooth();
text("send",25,40);
noSmooth();
}
void keyPressed(){
if(keyCode != LEFT && keyCode != RIGHT && keyCode != UP && keyCode != DOWN && keyCode != SHIFT && keyCode != BACKSPACE){
screentext[x][y] = key;
}
if(keyCode == UP){
y--;
blink = 0;
}else if(keyCode == DOWN){
y++;
blink = 0;
}else if(keyCode == LEFT){
x--;
blink = 0;
}else if(keyCode == RIGHT){
x++;
blink = 0;
}else if(keyCode == BACKSPACE){
if(x>0){
x--;
}
if(y>0 && x==0){
y--;
}
screentext[x][y] = ' ';
}else if(keyCode == ENTER){
y++;
x=0;
}else if(keyCode == TAB){
x=x+3;
}else if(keyCode == SHIFT){
}else{
x++;
}
}
boolean mouseisin(int x1, int y1,int x2,int y2) {
if(mouseX > x1 && mouseX < x2 && mouseY > y1 && mouseY < y2) {
return true;
}
else {
return false;
}
}
color invert(color input) {
return color(255-red(input),255-green(input),255-blue(input));
}
void send(){
String temp_save[] = loadStrings(file);
String temp_extend[] = new String[temp_save.length() + 1];
for(i=0; i<temp_save.length+1; i++){
temp_extend[i] = temp_save[i];
}
String temp_submit;
for(int i=0; i<30; i++){
for(int j = 0; j<100; j++){
temp_submit = temp_submit + screentext[j][i];
}
}
temp_submit=trim(temp_submit);
temp_extend[temp_extend.length()] = temp_submit;
saveStrings(file, temp_extend());
}
1