Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a html tag
<html><body>You scored <b>192</b> points.</body></html>
I want to convert the html to string for this i use the code
String ni= Html.fromHtml((String) "<html><body>You scored <b>192</b> points.</body</html>").toString();
and i got the out put as
You scored 192 points.
But i want the out put as
You scored 192 points.
That is 192 should be bold. I want to print this result using a bluetooth printer. so can't use webview for view that.So is there any API to convert the HTML to String without change its format.
The problem is, that you're assigning the return-value of the Html.fromHtml()-method to a String-object. The method returns a Spanned-object, which is able to hold information like text-markup. By assigning it to a String, the object "forgets" these information.
This is possible, because the Spanned-interface implements the CharSequence-interface (therefor is a char-sequence) and String implements CharSequence.
This should however work:
Spanned ni = Html.fromHtml((String) "<html><body>You scored <b>192</b> points.</body</html>").toString();
In case your are trying to show that in TextView, you can use below code,
textView.setText(Html.fromHtml("YOUR HTML STRING"), TextView.BufferType.SPANNABLE);
Give it a try
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a string array
String[] albumnames;
now how to take a string from particular index position with limited number of charachters.
For example,
if, albumnames[position] have value "abcdefghijk"
then i want to take the first 5 characters only.
That is "abcde".
The substring method of String can be used to achieve this. Try
String s = albumnames[position].substring(0,5);
See substring docs
albumnames[position].substring(0,5);
you can see the methods in String class, like substring, indexof
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have to create a random cellnumber 07939393914 for automation testing purpose.
Last 079393(5 digits) digits should change randamly.. each time test runs..
Can any one suggest JAVA code for this ? or else Selenium Java code ?
Thanks
Is this a number or a String? I ask as it has a leading zero.
Take you initial number as 7939300000
then add to it Math.round(Math.Random()*10000)
If you want it as a String, take your string as "079393" and use Integer.toString on the result above, then concatentate them
Use RandomStringUtils class.
String randomNumbers = RandomStringUtils.randomNumeric(5);
String phNo = 079393+randomNumbers;
var num=Math.ceil(Math.Random()*100000)
for random first 5 digit numbers
and add
var your_last_5digits; //as string to your last 5 digits
cellNumber='0'+num+your_last_5digits;
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am new to java need help
the main string i have is
eg.
"String1/string2/string3/string4/all_free.sdx"
"file1/file2/string3/string4/all_free.sdx"
the end result i need is to be able to isolate and get string3
i can indexof but not able to achieve it in few steps need brainy people help as i am new to JAVA
If you know it's the third item that you want to get, one simple approach could be using split method, like this:
String myString = "String1/string2/string3/string4/all_free.sdx";
String string3 = myString.split("/")[2];
The call of split("/") produces an array of strings like this:
{"String1", "string2", "string3", "string4", "all_free.sdx"}
Now you can apply the subscript operator to grab the element that you want.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am fairly inexperienced in Java as well as Android. I am trying to retrieve a phone number stored in one of the contacts of the android phone emulator. While I am successful to fetch it, the number has been returned in a string in a format like "(987) 654-3210".
I want to convert it to integer or long. How can I do that? If I use Integer.parseInt(String number), it returns a NumberFormatException. Failed while tried using Long.valueOf(String number) too. What should I do then? I want it like "9876543210" without any braces or hyphens.
using the long for storing number will be better
String str="(987) 654-3210";
String stt=str.replaceAll("\\D+","");
long num= Long.parseLong(stt);
System.out.println(num);
This should be simple. You could use regex in java to do this like below
phoneStr = str.replaceAll("\\D+","");
This will delete the non digits from the string and give you only numbers. Then you can use
int number = Integer.parseInt(phoneStr);
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a text file which contains the follwing
{"sno":"1c8d1d7eaa32ff3f58a8822111276d5a","at":"app","tt":{"AppParam1":"AppParamValue1","AppParam2":"AppParamValue2"}},"c":{"dt":"Microsoft XDeviceEmulator","pn":"WP","pv":"8.0.9832.0"}
In java I want to find 'sno', 'pn' and 'pv' and replace the values of (what I mean is) currently the above text file has
"sno" has value "1c8d1d7eaa32ff3f58a8822111276d5a"
"pn" has value "WP"
"pv" has value "8.0.9832.0"
New values
"sno" has to be changed to "637829"
"pn" has to be changed to "XYZ"
"pv" has to be changed to "2.2.4.0"
Your help is much appreciated !
Thanks
That's a JSON object.
Convert that string to a JSON object, change the values and then convert it again to a string.
Here you can read about JSON objects in java: http://www.json.org/java/
And here an easy tuto on how to work with them: http://answers.oreilly.com/topic/257-how-to-parse-json-in-java/
You can convert it into JSON, make you changes and then convert it back to string.
Or if you really want to replace these values by yourself, you can use these lines :
yourstring = yourstring.replaceFirst("\"sno\":\"[^\"]+\"", "\"sno\":\"637829\"");
yourstring = yourstring.replaceFirst("\"pn\":\"[^\"]+\"", "\"pn\":\"XYZ\"");
yourstring = yourstring.replaceFirst("\"pv\":\"[^\"]+\"", "\"pv\":\"2.2.4.0\"");
Only if there are no way theses key can be found elsewhere in the string