amandricel
Lurker
Hello,
I have a problem with a current project.It's a simple one,i know,but i'm not sure how to solve it.I need to make a application that shuffles a sentence something like this:
before:I am going to school today.
after:I am giong to shcool tdaoy.
I need to change only the middle of each word and keep the fist and last letter intact.
This is what i've done so far:
package alex.com;
import java.util.ArrayList;
import java.util.Collections;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MixWords extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText TextEdit = (EditText) findViewById(R.id.TextEdit);
final TextView mix =(TextView) findViewById(R.id.mix);
final Button button = (Button) findViewById(R.id.proces);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action when clicking
MixMe(TextEdit.getText().toString());
}
private void MixMe(String word) {
// TODO Auto-generated method stub
ArrayList<Character> all = new ArrayList<Character>();
for (int i = 1; i < TextEdit.length()-1; i++) {//starts from the second character
all.add(word.charAt(i));
}
Collections.shuffle(all);
char a = word.charAt(0);//The first char
char b = word.charAt(TextEdit.length()-1);//The last char
String result = "";
result+=a;
for (Character character : all) {
result += character;
}
result+=b;
mix.setText(result);//shows the the mix string
}
});
}
}
I need to search for whitespaces and somehow split the string in order to jumble only the middle of the string.Any ideas?Thank you
I have a problem with a current project.It's a simple one,i know,but i'm not sure how to solve it.I need to make a application that shuffles a sentence something like this:
before:I am going to school today.
after:I am giong to shcool tdaoy.
I need to change only the middle of each word and keep the fist and last letter intact.
This is what i've done so far:
package alex.com;
import java.util.ArrayList;
import java.util.Collections;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MixWords extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText TextEdit = (EditText) findViewById(R.id.TextEdit);
final TextView mix =(TextView) findViewById(R.id.mix);
final Button button = (Button) findViewById(R.id.proces);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action when clicking
MixMe(TextEdit.getText().toString());
}
private void MixMe(String word) {
// TODO Auto-generated method stub
ArrayList<Character> all = new ArrayList<Character>();
for (int i = 1; i < TextEdit.length()-1; i++) {//starts from the second character
all.add(word.charAt(i));
}
Collections.shuffle(all);
char a = word.charAt(0);//The first char
char b = word.charAt(TextEdit.length()-1);//The last char
String result = "";
result+=a;
for (Character character : all) {
result += character;
}
result+=b;
mix.setText(result);//shows the the mix string
}
});
}
}
I need to search for whitespaces and somehow split the string in order to jumble only the middle of the string.Any ideas?Thank you

