Again N Again Split the string with "#" [closed] - android

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I want to split the String with the # symbol
'#Happy#sad#Angry#Tear and so on`
I don't know how many times user enters hashtags so how can I split that String?
I tried this:
allhashtag= String.valueOf(edt_hashtag.getText());
String tag1[] =allhashtag.split("#");
String tag2= tag1[0];

Try for loop for split String when we don't know how many characters in String
Try this code:
String s = allhashtag;
if(s.toString().contains("#"))
{
String tags[]=s.toString().split("#");
for (String tag : tags)
{
Log.e("tag",""+tag);
}
}

Related

Regular expression for song name in android [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
In my application I want to display the song's name. Now it is showing the entire song path, like this
String song_name = /storage/Music/Lean on.mp3
but I want to display only the song's name, that means
String song_name = Lean on.mp3
Can any one help me with the regular expressions used for extracting the name of song from the file path?
You can use subString function with combination of LastInedexOf function.
please find below example
String path=":/storage/Music/Lean on.mp3";
String filename=path.substring(path.lastIndexOf("/")+1);

Why I am not getting the correct output for array.set? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
Firstly, I am storing the data in ArrayList.Now based on my index(current position) I want to replace that data with new data,but what I am getting is
old data,old data,old data,true,true,new data,new data....
Any suggestions
ArrayList<String> arr = new ArrayList<String>();
if (arr.isEmpty()) {
for(int i = 0;i<=mcq.size();i++) {
arr.add(s);
}
} else {
arr.set(currentPosition, String.valueOf(arr.add(s)));
}
"s" is a String value I am getting from somewhere else.
This looks really weird:
arr.set(currentPosition, String.valueOf(arr.add(s)));
ArrayList.set changes the elements stored at currentPosition. You want it to change it to the string value of what arr.add returns.
ArrayList.add returns a boolean, so there you get your true values from.
I think you want to do arr.set(currentPosition, s);

If edit text contains spaces then show error [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
EditText text = (EditText)findViewById(R.id.text);
if(condition)
{
}
if edittext containing space bar then show error
There should be no " " space in the EditText is what you want.
Nobody will provide you with a ready working code. Here are some pointers to proceed.
String a = text.getText().toString();");
This will help you get the string in the edittext
So you have the string that the user had entered in the edittexxt.
No you need to use a simple function that will check if a character is present in the string.
String s= String from edittext;
boolean p=s.contains(" ");
if(p)
//call function for error
else
//safe to proceed
Use the following code to show error.
EditText text = (EditText)findViewById(R.id.text);
if(text .getText().toString().contains(" "))
{
text.setError("Field cannot be have space.");
}

How do I return an int from EditText and than show that number in Toast? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am a beginner at programming Android, please help with this simple project.
I want an integer to show up in toast, which I write in textBox. I do not know what to put in the highlighted part here.
Sorry for the link, but I cannot post the picture
You need to use the getText() method to get the text the user entered.
Change the myEdit declaration to:
final EditText myEdit = ... ;
and then use:
Toast.makeText(MainActivity.this, myEdit.getText().toString(), ...

adding string as integer [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
in my application i have got 0.00 in edit text.next when i enter 2or3 or any digit its getting concat with 0.00 and getting 0.003.
if(item.equals("0.00")){
item=item+string;}
i changed the code.but this time too its getting an error
if(item.equals("0.00")){
int a=Integer.parseInt(item.toString());
int b=Integer.parseInt(string.toString());
int c=a+b;
item=String.valueOf(c);}
If you are using decimal places then you will want to use a data type that supports those, such as double. Try this:
double d = Double.parseDouble(item.toString());
NOTE: If both your variables are of string type, then you won't need to use toString()
You want O.OO but still using Integer. Try using FLOAT.
Also, FLOAT is NEVER a perfect value. So you might have .XX added.
You have an error, because "0.00" has decimal places, so it is parsed as a floating point number, not integer.
Parse it as a double:
String item = "0.00";
double result = Double.parseDouble(item) + 0.03; // result is 0.03

Categories

Resources