I want to send bold text via a bot.
To send it as a normal person you would have to type 2 stars in front and behind the message, but this doesn't work for the bot. I have searched for a solution here but most bots are developed in PHP or Python.
`String a = emoji+"**dump alert**\n";
String b = "Date and time: ";
String c = month+" "+date.format(format1)+" / "+date.format(format2)+"\n";
String d = "Exchange: "+exc;
return a+b+c+d;`
For work with html tags in Text you need ON this options.
You can do it edit this flag:
message.enableHtml(true);
After this you can set bold text use this example:
String text = "<b>Bold text</b>";
When you work with Markdown you should use only one star *bold*
It should work with html tags. So instead of
String a = emoji+"**dump alert**\n";
try using this
String a = emoji+"<b>dump alert</b>\n";
Related
I have a website that is in plain text. The website is in a format like this:
{"code1":"Text I want copied","code2":"Second text I want to copy"}
Every time the website refreshes though, the texts I want copied change in length. I am curious how I could retrieve the text starting after ' :" ' and before ' ", ', using Java. I want the same thing to happen with the second text as well. I also would like to remove the html tags. Help will be greatly appreciated.
Using the org.json library, you could parse the JSON like:
String myJSONString = "{\"code1\":\"Text I want copied\",\"code2\":\"Second text I want to copy\"}";
JSONObject object = new JSONObject(myJSONString);
String[] keys = JSONObject.getNames(object);
String firstText = (String) object.get(keys[0]);
String secondText = (String) object.get(keys[1]);
For parsing the web page, you can use the JSoup library. See an example from this answer.
I'm currently in the progress of making a java application, one of the functions is showing related emails and documents.
But the full path to the email (on a sharepoint server) is displayed in the application, for obvious reasons the number of characters depends on the title of the email and the location.
But they all have the same in common, there are ALWAYS 3 slashes in the title.
Like this: Myserver/client/caseID/Title of Email here
Is it possible to get Java to "count" the number of slashes and just delete everything before the third slash?
Use the Split function to achieve this.
String value="Myserver/client/caseID/Title of Email here";
value=value.split("\\/")[3];
System.out.println("your value is "+value);
Here is an example:
String s = "Myserver/client/caseID/Title of Email here";
int i = s.lastIndexOf('/');
if (i != -1)
System.out.println(s.substring(i));
else
System.out.println("no slashes");
Using the replaceFirst function is one way to go:
String yourString = "Myserver/client/caseID/Title of Email here";
System.out.println(yourString.replaceFirst("([^/]+/){3}", ""));
try this
s = s.replaceFirst(".*?/.*?/.*?(?=/)", "");
What's the difference between this
conversationPane.setText(msg + conversationPane.getText());
and this?
conversationPane.setText(conversationPane.getText() + msg);
I know thah the second line does not print the message but Why!? I'm making a chat and the new messages should appear below the previous message (Like in a normal chat) but with the first line the new messages appear up all the conversation.
I use JEditorPane whith content type HTML because the chat contents smileys and this things, if I change the content type to textPlain the second line works perfectly.
I'm looking for the solution and find things with insertString using a Document and Attributes but I don't undestand how used and if this can solve my problem.
I don't know exactly why. I know, however, it's related with text being appended after a </html> tag. When you setText() on a JEditorPane with text/html content type, <html> tags are automatically added.
I dealt with a similar problem before. The way I fixed it was saving all the text in a string, then setting it in the pane:
String s = "";
...
s += msg;
conversationPane.setText(s);
Use insertBeforeStart method from HTMLDocument.
Scala example:
//set basic document structure
text = "<html><title></title><body><span id='Text'></span></body></html>"
//get Document as HTMLDocument
val htmlDoc = peer.getDocument.asInstanceOf[javax.swing.text.html.HTMLDocument]
//get span element with id=Text, before which text will be inserted
val bottomText = htmlDoc.getElement("Text")
//append function with optional line feed
def appendXml(xml:String, lineFeed:Boolean) = { htmlDoc.insertBeforeStart(bottomText, s + (if (lf) "<br>" else "" )); }
I'm quite new to Android and I'm trying to display some chemical formulas in a textView which is contained in a customListView.
I'm fetching all datas from xml parsing, then I wish to display the formula, such as C₉H₈O₄.
But I can see only 1-4 digits.
I'm converting from "normal" to "subscript" in this way
str = str.replaceAll("0", "\u2080");
str = str.replaceAll("1", "\u2081");
str = str.replaceAll("2", "\u2082");
str = str.replaceAll("3", "\u2083");
str = str.replaceAll("4", "\u2084");
str = str.replaceAll("5", "\u2085");
str = str.replaceAll("6", "\u2086");
str = str.replaceAll("7", "\u2087");
str = str.replaceAll("8", "\u2088");
str = str.replaceAll("9", "\u2089");
str contains the formula fetched from the xml file.
The strange behavior is that I can see in the Logcat the formula as it should be.
I also tried with customs fonts but nothing.
Here are two results:
the first is with normal font, the second with a custom one
https://www.dropbox.com/s/jyk64p700up14db/cella.jpg
https://www.dropbox.com/s/ab9h1b45j2hrods/Schermata%2003-2456370%20alle%2022.05.45.png
Over the web I can read as a solution using something like
setText(Html.fromHtml("X<sub>2</sub>"));
but I really don't know how to use it in my case.
Any suggestion?
It will not be easy trying to solv that problem with Html.fromHtml("X<sub>2</sub>")
you need a lib that can help you to achieve that
(JEuclid is a complete MathML rendering solution, consisting of:) http://jeuclid.sourceforge.net/
Look at the example and you'll get a way to resolve your issue
Other alternatives for rendering math expressions with TeX:
http://jmathtex.sourceforge.net/
http://sourceforge.net/projects/snuggletex/
http://forge.scilab.org/index.php/p/jlatexmath/
Finally I solved the problem: It was a font issue.
I just used Calibri and It works!
I wanted to change width="xyz" , where (xyz) can be any particular value to width="300". I researched on regular expressions and this was the one I am using a syntax with regular expression
String holder = "width=\"340\"";
String replacer="width=\"[0-9]*\"";
theWeb.replaceAll(replacer,holder);
where theWeb is the string
. But this was not getting replaced. Any help would be appreciated.
Your regex is correct. One thing you might be forgetting is that in Java all string methods do not affect the current string - they only return a new string with the appropriate transformation. Try this instead:
String replacement = 'width="340"';
String regex = 'width="[0-9]*"';
String newWeb = theWeb.replaceAll(regex, replacement); // newWeb holds new text
Better use JSoup for manipulating and extracting data, etc. from Html
See this link for more details:
http://jsoup.org/