6 Replies - 5984 Views - Last Post: 04 October 2011 - 05:39 PM Rate Topic: -----

#1 pgfdbug  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 63
  • Joined: 14-April 08

Strcat equivalent in Java

Posted 04 October 2011 - 12:53 AM

I need to find a way to make the simple stuff below return ab.wav instead of a.wav talking over b.wav. I understand "c" and am learning Java. I would use a simple strcat call in c, for Java Im at a lost.

 if(data.contains ("A")){
                            new AudioPlayer("A.wav").start();
						sign = A;
					}
                        if(data.contains ("B")){
                            new AudioPlayer("B.wav").start();
						sign = B;
					}
                        if(data.contains ("D")){
                            new AudioPlayer("D.wav").start();
						sign = D;
					}
                       if (true){
                           return;}


Is This A Good Question/Topic? 0
  • +

Replies To: Strcat equivalent in Java

#2 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1819
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Strcat equivalent in Java

Posted 04 October 2011 - 01:06 AM

strcat is used to concatenate strings in c? In java you can use string builder, look a tutorial here also
Was This Post Helpful? 0
  • +
  • -

#3 cfoley  Icon User is online

  • Cabbage
  • member icon

Reputation: 2021
  • View blog
  • Posts: 4,191
  • Joined: 11-December 07

Re: Strcat equivalent in Java

Posted 04 October 2011 - 09:06 AM

Or:

String a = "A";
String b = "B";
String c = a + b;
System.out.println(c); // prints AB

Was This Post Helpful? 0
  • +
  • -

#4 pgfdbug  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 63
  • Joined: 14-April 08

Re: Strcat equivalent in Java

Posted 04 October 2011 - 03:04 PM

The data will sometimes have just A, sometimes just B, sometimes A&B and then other times A,B&D. That is where Im having the trouble. The data changes every time its not always the same output.
Was This Post Helpful? 0
  • +
  • -

#5 cfoley  Icon User is online

  • Cabbage
  • member icon

Reputation: 2021
  • View blog
  • Posts: 4,191
  • Joined: 11-December 07

Re: Strcat equivalent in Java

Posted 04 October 2011 - 03:22 PM

+ is the String concatenation operator in Java. Unfortunately, I con't work out what you are trying to do from your post. I'm happy to help if you explain further.
Was This Post Helpful? 0
  • +
  • -

#6 pgfdbug  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 63
  • Joined: 14-April 08

Re: Strcat equivalent in Java

Posted 04 October 2011 - 05:15 PM

I have a searcher looking for incoming data A,B, and D. When the searcher sees the data it sends out and audible alert, the .wav files. Now the problem the data is completely random, sometimes you might have just "A" or sometimes you might have "A" and "B", another might be "A", "B", and "D" and so on. When the searcher sees A and B the sound files talk over each other. I need to make it so if there are multiple hits in a search it will play sound file abd.wav instead of a.wav, b.wav, and d.wav all over each other. Im kind of lost in Java and everything I have read and tried I can not get the results Im looking for. I did it like this in c.

sprintf(soundstring, "soundtest ");
		
		if(A==1)
		{
			if(beforeflag)
			strcat(soundstring, "A");				
			beforeflag = 1;
		}
		if(B==1)
		{
			if(beforeflag)
			strcat(soundstring, "B");				
			beforeflag = 1;
		}
		if(a==1)
		{
			if(beforeflag)
			strcat(soundstring, "C");				
			beforeflag = 1;
		}
strcat(soundstring, ".wav");
system(soundstring);

Was This Post Helpful? 0
  • +
  • -

#7 cfoley  Icon User is online

  • Cabbage
  • member icon

Reputation: 2021
  • View blog
  • Posts: 4,191
  • Joined: 11-December 07

Re: Strcat equivalent in Java

Posted 04 October 2011 - 05:39 PM

Something like this:

String soundstring = "";
for(String s : new String[]{"D", "B", "A"}) {
  if (data.contains(s)) {
    if (beforeflag) 
      soundString = s + soundstring;
    beforeflag = true;
  }
}



or if the beforeflag stuff is not important

String soundstring = ".wav";
for(String s : new String[]{"D", "B", "A"}) {
  if (data.contains(s))
    soundString = s + soundString;
}

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1