|
Author |
Topic: splitstrings to array (Read 1776 times) |
|
un_chien_andalou25
|
splitstrings to array
« on: Nov 16th, 2004, 8:10pm » |
|
i was attempting to splitstrings into an array and then utilize this as variable data, but i keep running into problems. i have talked to others who have had similar problems with different projects - is this a problem in our coding or is there a bug in processing? the code comes from a script integrating carnvirore and sonia, but the problems seem to be in the "splitstrings" near the top of the post, and the 'if' statement at the bottom of the post. code: String packet; String list[] = splitStrings(packet); Sample mySample; void setup(){ size(800, 200); textFont(loadFont("GillSans.vlw.gz"), 24); Sonia.start(this, 44100); mySample = new Sample("sine.aif"); } { //start listening to carnivore CL = new CarnivoreListener(); CL.startListening(); } void loop(){ background(50,50,50); fill(130,130,130); text("data from Carnivore", 10, 30); packet = CL.getPacket(); fill(200,200,200); text(packet, 10, 50); if (list[7] == "0000"){ mySample.play(); // play the sample once. } }
|
|
|
|
fry
|
Re: splitstrings to array
« Reply #1 on: Nov 17th, 2004, 12:05am » |
|
what sort of problem is it, exactly?
|
|
|
|
un_chien_andalou25
|
Re: splitstrings to array
« Reply #2 on: Nov 30th, 2004, 5:32pm » |
|
it seems as though string data is being placed into the array - and that i can get access to this data by just printing it as text, but if i try to refer to any part of the array as a variable, i am unable to utilize the data stored there.
|
|
|
|
un_chien_andalou25
|
Re: splitstrings to array
« Reply #3 on: Nov 30th, 2004, 9:15pm » |
|
or, to rephrase: i basically need to grab packet data from carnivore and run it through some conditional logic. i am able to get the data into an array using splitstrings, but i am then unable to access the data. how can i access this list data for a conditional function? it seems that i can place the value in the array, but that the conditional function is not being executed. roughly: string list[] = splitStrings(packet); if (list[7] == "0000"){ mySample.play(); // play the sample once. }
|
|
|
|
TomC
|
Re: splitstrings to array
« Reply #4 on: Dec 1st, 2004, 1:16am » |
|
To test if Strings are lexicographically equal, use String's equals() method. The == operator only checks if two Strings are the same object. e.g. Code: String a = new String("test"); String b = new String("test"); println(a == b); // false, not the same objects println(a.equals(b)); // true, contain the same text |
| But there is a catch. When initialising Strings with constants (and not 'new'), then they will refer to the same object. This can be confusing... e.g. Code: String a = "test"; String b = "test"; println(a == b); // true, both refer to the "test" constant println(a.equals(b)); // true, contain the same text |
| (edit: I actually got this wrong first time. Time for bed!)
|
« Last Edit: Dec 1st, 2004, 1:27am by TomC » |
|
|
|
|
|