Splitting a Java String by the pipe symbol using split(|)
You need
test.split("\\|");
split
uses regular expression and in regex |
is a metacharacter representing the OR
operator. You need to escape that character using \
(written in String as "\\"
since \
is also a metacharacter in String literals and require another \
to escape it).
You can also use
test.split(Pattern.quote("|"));
and let Pattern.quote
create the escaped version of the regex representing |
.
Splitting string with pipe character (|)
|
is a metacharacter in regex. You'd need to escape it:
String[] value_split = rat_values.split("\\|");
How can I force clients to refresh JavaScript files?
As far as I know a common solution is to add a ?<version>
to the script's src link.
For instance:
<script type="text/javascript" src="myfile.js?1500"></script>
I assume at this point that there isn't a better way than find-replace to increment these "version numbers" in all of the script tags?
You might have a version control system do that for you? Most version control systems have a way to automatically inject the revision number on check-in for instance.
It would look something like this:
<script type="text/javascript" src="myfile.js?$$REVISION$$"></script>
Of course, there are always better solutions like this one.
How to split a string on | (pipe) in Java
You'll have to escape your pipe character (split takes a regular expression as argument and therefore "|" is a control character):
str.split("\\|");
Please note: the resulting array contains an empty string at the beginning since you have "|" at start of your string.
Split a String on | (pipe) in Java
|
is a special symbol in regular expression. Use \\|
instead.
I'll explain why I appended 2 slashes. To escape the |
, I need \|
. However, to represent the string \|
, "\\|"
is required because \
itself needs to be escaped in a string lateral.
And, as xagyg has pointed out in the comment, split will treat the parameter as a regular expression. It will not be treated as a plain string.
In this use case, you may be interested to learn about Pattern.quote. You can do Pattern.quote("|")
. This way, none of the characters will be treated as special ones.
Splitting a string on the double pipe(||) using String.split()
String.split()
uses regular expressions. You need to escape the string that you want to use as divider.
Pattern has a method to do this for you, namely Pattern.quote(String s)
.
String[] split = str.split(Pattern.quote("||"));
Using git for plugin development
I think your best option is to try to change the project layout such that each extension is more self-contained, I.E. resides in it's own directory under say, /extensions.
On framework startup/testrun, scan that directory and dynamically load the extensions. That way you not only makes it easy to develop and work with git, but you also makes it easier for various packaging-options, I.E. tarballs. It makes it easy for the user to see what extensions are used.
You would then also allow 3d-parties to develop "out-of-tree" extensions easily using their VCS of choice.
Related Topics
Maven: Add a Dependency to a Jar by Relative Path
Netbeans Gui Editor Generating Its Own Incomprehensible Code
Does a Lambda Expression Create an Object on the Heap Every Time It's Executed
Difference Between Inheritance and Composition
Org.Xml.Sax.Saxparseexception: Content Is Not Allowed in Prolog
How to Read from a Inputstream With a Timeout
Value Change Listener to Jtextfield
Are Static Methods Inherited in Java
Java Runtime.Getruntime(): Getting Output from Executing a Command Line Program
Initialization of an Arraylist in One Line
Questions About Java'S String Pool
Something Seems Wrong With the Layout, Jbutton Showing Unexpected Behaviour At Resize of the Window
Difference Between Static Methods and Instance Methods
Is It Safe to Use a Static Java.Sql.Connection Instance in a Multithreaded System