I want to replace Encode::forUri with something that is not depricated. Does anyone know what method should I use to cover that up? I can't use forUriComponent() because I have to convert an link, not a query, and also forUriComponent() doesn't convert all the characters as forUri() did
Code example:
private static final ImmutableList<UnaryOperator> ENCODING_CHAIN_URL_IN_HTML_ATTRIBUTE = ImmutableList.of(Encode::forUri, EsEncode::uriAsSafeSchemeUri, Encode::forHtml);
Thanks!
I think you should use
URLEncoder.encode("NAME", "UTF-8");
https://docs.oracle.com/javase/8/docs/api/java/net/URLEncoder.html#encode-java.lang.String-java.lang.String-
Example
URLEncoder.encode(
"urlStringParams",
java.nio.charset.StandardCharsets.UTF_8.toString()
)
Related
How can is use string formatting on the
<string-array><item> - resource in Android?
Should i do it like in the following example(and how should i do it if yes)...
<string-array name="notification-msgs">
<item>%s sent you a message.</item>
<item>%s answered to your Story</item>
</string-array>
or what kind of technique is common to use in this case?
I only know how to Format string resources.(with getString(R.id.mystring,replacevalue))
Thanks for any help!
EDIT:
I tried to use getStringArray(), but this method does not accept more then one argument, which just is an Array-Ressource.
Unfortunately there is no direct way provided by Android to achieve this. Best you can do is:
String.format(getResources().getStringArray(R.array.notification-msgs)[0], "Someone")
Android supports formatting with getString(String str,Object... args). Link here
Or you can wrap formatting with a method.
public static String formatString(String pure,Object... args){
return String.format(pure,args);
}
//Or
public static String formatString(int id,Context context,Object... args){
String pure = context.getString(id);
return String.format(pure,args);
}
I personally prefer second approach, it is easy to mutable in the future.
I am new in Jython.. I want to use the string formatting str.format() in Jython (look here).
If I try to use it like this:
testText = 'This is a {word}'
and later on
str.format(testText, word='test!')
the exception text is:
Error: exceptions.AttributeError instance of 'org.python.core.PyReflectedFunction' has no attribute 'format'
What do I have to add in the imports/classpath or anywhere?!
Thanks for your help!!
Kind regards
Try this:
print "%(map_1)s %(map_2)s" % {'map_1':'Hello','map_2':'World'}
I'm trying to configure a request to http: //where.yahooapis.com/v1/places.q(name_here);count=50?....
Not the best solution, I guess, but I tried
#GET("/v1/{location}")
Places getLocations(#Path("location") String locationName);
and pass there
getLocations("places.q(" + locationName + ");count=50");
But it still doesn't work as the string (); is translated into %28%29%3B.
Can you suggest any solutions? It would be better to dinamycally modify only the name_here part, something like
#GET("/v1/places.q({location});count=50)
If it is not possible how do I have to pass symbols (); so that they are converted correctly?
I just tried
#GET("/v1/places.q({location});count=50")
Places getLocations(#Path("location") String name)
a bit later and it works fine. I thought it will insert something like "/" or modify it, but it does exectly what I need.
I'm trying to read in a csv in the hdfs, parse it with cascading, and then use the resulting tuple stream to form the basis of regex expressions in another tuple stream using RegexParser. As far as I can tell, the only way to do this would be to write a custom Function of my own, and I was wondering if anybody knew how to use the Java API to do this instead.
Pointers on how to write my own function to do this inside the cascading framework would be welcome, too.
I'm running Cascading 2.5.1
The best resource for this question is the Palo Alto cascading example tutorial. It's in java and provides examples of a lot of use cases, including writing custom functions.
https://github.com/Cascading/CoPA/wiki
And yes, writing a function that allows an input regex that references other argument inputs is your best option.
public class SampleFunction extends BaseOperation implements Function
{
public void operate( FlowProcess flowProcess, FunctionCall functionCall )
{
TupleEntry argument = functionCall.getArguments();
String regex = argument.getString( 0 );
String argument = argument.getString( 1 );
String parsed = someRegexOperation();
Tuple result = new Tuple();
result.add( parsed );
functionCall.getOutputCollector().add( result );
}
}
I need to clear the warning or say error message,which will be the best one to choose
setMessage(null)
or
by using StringUtils.EMPTY - i just want to know the exact way of using StringUtils.EMPTY,it would be helpful...
Thanks & Regards.
Do not use null.
Since it's a message you might showing it some where,If you set it to null,it displays as "null" to end user.
Try like ,
private static final String EMPTY_STRING = "";
setMessage(EMPTY_STRING );
on there other hand you can check with isEmpty method,instead of checking null.