Android, how to replace slashes in path - android

i have an image path : "UploadFile\\/UserProfile\\/Female.jpg". How to replace "\\/" with "/"?
i have tried :
replaceAll("\\/","/")
replaceAll("\\\\/","/")
Code:
adapter_profilepic = objUser.getProfilePicture().replaceAll("\\/","/");

This works :
String src = "UploadFile\\/UserProfile\\/Female.jpg";
src = src.replaceAll("\\\\/","/");
System.out.println(src);
output:
UploadFile/UserProfile/Female.jpg
You said you tried it, but check it again.

According documentation your string is used as regular expression. Why you don't using replace:
String adapter_profilepic = objUser.getProfilePicture().replace("\\\\/","/");

Related

Not getting a new line in kotlin text view on android studio

fun SubmitOrder(view: View) {
/* pricing of coffee */
val total = quantity * 5
val s: String = ("$$total.00")
money.text = ("Total : $s\nThank You!").toString()
//This is calling On click listener
Toast.makeText(this, "order_Submitted", Toast.LENGTH_SHORT).show()
}
In this code, I need a new line before Thank You! in money.text but I am not getting any new line I am new in android development so, am not able to point out the mistake.
Let's go thru your code line by line:
val s: String = ("$$total.00")
s is a bad variable name, as it's not descriptive at all
you don't need the (braces)
the :String here is optional. In such an obvious case i would emit it.
A $ is a sign to the kotlin compiler to include the following variable. Therefore, you can't use the $ when you mean "US-Dollar". See this post on how to escape it
While ".00" works, it's no good style. I suggest you use string formatting as described here.
can be written as val s = "\$ ${String.format("%.2f", total)}"
you should wherever possible use string resources, but thats out of the scope of this answer
money.text = ("Total : $s\nThank You!").toString()
this is correct, but unnecessary verbose:
"Total : $s\nThank You!" is already a string, so there's no need to .toString()
braces are not needed
can be written as money.text = "Total : $s\nThank You!"

UISelector Using descriptionContains

I'm working on the automation script, where I'm trying to click on the element based on content-desc, The code I tried is
app_element = driver.find_element_by_android_uiautomator('new UiSelector().descriptionContains("Subway Surfers")')
app_element.click()
This works for me
But I want to know is it possible to store the 'Subway Surfers' in a string variable and assign it inside the descriptionContains("Subway Surfers")') like
content_description = 'Subway Surfers'
app_element = driver.find_element_by_android_uiautomator('new UiSelector().descriptionContains(content_description)')
Like this is it possible can any one help me on this
Try this:
content_description = 'Subway Surfers'
app_element = driver.find_element_by_android_uiautomator('new UiSelector().descriptionContains('+content_description+')')

How to check if a string has a specified character?

I am new to android studio and kotlin. I need to find a way to check if a string contains a char, which is, in this case, "/"
I want to form a piece of code in the following manner:
if (string input contains a character "/") = true {
<code>
}
else{
<code>
}
Please tell me how to do this, and if possible, give me the code I'll need to specify as the condition.
You can use contains, like this:
val a = "hello/"
val b = a.contains("/")
When the string has the character will return true.

Android TextView not showing multiple lines, even though String has newlines [duplicate]

For the input text:
<p>Arbit string <b>of</b><br><br>text. <em>What</em> to <strong>do</strong> with it?
I run the following code:
Whitelist list = Whitelist.simpleText().addTags("br");
// Some other code...
// plaintext is the string shown above
retVal = Jsoup.clean(plaintext, StringUtils.EMPTY, list,
new Document.OutputSettings().prettyPrint(false));
I get the output:
Arbit string <b>of</b>
text. <em>What</em> to <strong>do</strong> with it?
I don't want Jsoup to convert the <br> tags to line breaks, I want to keep them as-is. How can I do that?
Try this:
Document doc2deal = Jsoup.parse(inputText);
doc2deal.select("br").append("br"); //or append("<br>")
This is not reproducible for me. Using Jsoup 1.8.3 and this code:
String html = "<p>Arbit string <b>of</b><br><br>text. <em>What</em> to <strong>do</strong> with it?";
String cleaned = Jsoup.clean(html,
"",
Whitelist.simpleText().addTags("br"),
new Document.OutputSettings().prettyPrint(false));
System.out.println(cleaned);
I get the following output:
Arbit string <b>of</b><br><br>text. <em>What</em> to <strong>do</strong> with it?
Your problem must be somewhere else I guess.

how to fetch `style="background-image: url` using selenium webDrive?

I grabbed this element using selenium webDrive:
<div class="body" style="background-image: url('http://d1oiazdc2hzjcz.cloudfront.net/promotions/precious/2x/p_619_o_6042_precious_image_1419849753.png');">
how can I fetch the value: http://d1oiazdc2hzjcz.cloudfront.net/promotions/precious/2x/p_619_o_6042_precious_image_1419849753.png ?
I'm not sure as this is an inner value, and not just an "src" attribute.
getCssValue(); will help you
WebElement img = driver.findElement(By.className('body'));
String imgpath = img.getCssValue("background-image");
then you can split the unwanted string "url('"
PS : Remove the javascript tag in your question
Try this
var imgString = $(".body").css('background-image');
console.log (imgString.split("(")[1] // remove open bracket
.split(")")[0] // remove close bracket
);
Fiddle
You can try the following
some_variable=self.driver.find_element_by_xpath("//div[#class='body' and contains(#style,'url')]")
some_variable2=some_variable.get_attribute('style')

Categories

Resources