Java String Split with Pipe Character Not Working - Solution
If you are working on Java, you might have run into this issue when you try to split a string based on a pipe character ( "|"...
https://www.programming-free.com/2015/09/java-string-spilit-with-pipe-character.html
If you are working on Java, you might have run into this issue when you try to split a string based on a pipe character ("|"). It simply won't work. Split method in Java takes regex as an argument. There are certain characters including the pipe character which has special meaning in regex and are called meta characters. Here is a list of Java Regex meta characters
( ) [ ] { { \ ^ $ | ? * + . < > - = !
There are three ways to resolve this issue,
1. Use Pattern.quote()
Pattern is a class for handling regex expressions in Java. Pattern.quote() returns a literal pattern String for the specified String. Metacharacters or escape sequences in the input sequence will be given no special meaning.
String[] values =values.split(Pattern.quote("|"));
2. Use Escape Characters
This is simple. Just escape the pipe character with double slash.
String[] values = values.split("\\|");
3. Use StringTokenizer to Split
You can use StringTokenizer to split strings and avoid all regular expression issues.
public static String[] splitUsingTokenizer(String original, String delimiters) { StringTokenizer token = new StringTokenizer(original, delimiters); ArrayList<String> list = new ArrayList<String>(original.length()); while(token.hasMoreTokens()) { list.add(token.nextToken()); } return list.toArray(new String[0]); }
Keep yourself subscribed for getting programmingfree articles delivered directly to your inbox once in a month. Thanks for reading!
Java Swing Examples
ReplyDeleteThanks for that, it was a lifesaver
ReplyDeleteThank you for posting very useful tips! I found your website perfect for my needs.I always like your article because you have provide every time informative post..Essay Editor Service
ReplyDeletewow, awesome blog.Thanks Again. Much obliged 먹튀검증 I believe you are the person I was looking for 먹튀검증
ReplyDeleteMua vé tại Aivivu, tham khảo
ReplyDeletevé máy bay giá rẻ từ singapore về hà nội
book vé máy bay đi sài gòn
giá vé máy bay đà nẵng hà nội
vé máy bay đi nha trang
ve may bay di quy nhon binh dinh
Your site is very good and informational for me. We are the best suppliers of Custom Printed CBD Boxes in the UK. If anyone has interest in them please visit our website for more products.
ReplyDeleteReally nice and informative blog, keep it up. Thanks for sharing and I have some suggestions.
ReplyDeletePlease Visit thanks .
Such a great post I like it very much keep it up.
ReplyDeleteluxury Cube boxes
Donut boxes Alaska
On the off chance that you are seeing some issue with your Brother Printer as it is associated yet not printing, the explanation could be anything behind it. Nonetheless, you can fix this issue by doing some essential investigating. What's more, to assist you with this, this post has presented to you some data and guidelines to follow. Fix Brother printer not printing problemThus, go thoroughly.To start with, you should check for the paper stuck issue in your Brother Printer. There are times when you don't used the printer for quite a while and dust gets gathered in the printer that prompts trouble.Also, you need to check the ink filled in the cartridge whether it is filled deficiently or void. For this situation, you will not get any printer issues like Brother Printer associated yet not printing.In expansion, an unfilled or half-filled cartridge causes the issue yet additionally when the ink is filled more than the necessary ink it likewise raises a ruckus in getting prints.When you fill ink in the cartridge more than the necessary sum, it might flood and can impede the printer head.
ReplyDeleteAmazing product thanks for sharing with us It is very informative. If you need any type of boxes you can visit the link.
ReplyDeleteLingerie packaging Boxes wholesale
Holiday Party boxes Alaska
wishmenia com
ReplyDeleteYour site is excellent. I was really touched by this post. I'm so delighted to locate the write-up I have actually been trying to find for a very long time. I covet the number of individuals sympathize with your writing. You discover a great deal of expertise from my writing.바카라사이트
ReplyDeleteWhen I read your article on this topic, the first thought seems profound and difficult. There is also a bulletin board for discussion of articles and photos similar to this topic on my site, but I would like to visit once when I have time to discuss this topic. 안전토토사이트
ReplyDeleteNice blog and informative sentence. I really like it. Keep sharing more with us.
ReplyDeleteData Science Courses
it's really nice and meanful. it's really cool blog. Linking is very useful thing.you have really helped lots of people who visit blog and provide them usefull information 스포츠토토
ReplyDeleteAttractive, post. I just stumbled upon your weblog and wanted to say that I have liked browsing your blog posts. After all, I will surely subscribe to your feed, and I hope you will write again soon! 토토사이트
ReplyDeleteI appreciate dear this was an amazing article. I just love your post after reading and waiting for your next post also Visit us
ReplyDeleteDesert Snakes all need to be in habitats with certain things. Most of them live on land and they need fresh water to drink because they can get dehydrated. Some like more humid environments and some like dryer environments, but you don’t know which ones. There are many types of snakes, so this book will teach you about the different habitats of snakes and where they live, so that you can be more informed about them. This book includes pictures, lots of information and is perfect for children interested in snakes.
ReplyDeleteWe provide all kinds of electrical solutions you will need to grow and flourish. Powerhouse Express brings efficient, reliable and accessible solutions to your doorstep.
ReplyDeletehttps://powerhouseexpress.com.pk/
Because of the wonderful use of language, I thoroughly enjoyed reading it. https://cracksir.com/wavepad-sound-editor-crack/
ReplyDeleteVery useful info. Hope to see more posts soon! web design malta
ReplyDeleteThis could be the right blog for everyone who is desires to be familiar with this topic. You already know much its practically not easy to argue along (not that I just would want…HaHa). You certainly put the latest spin with a topic thats been discussing for decades. Excellent stuff, just great! luxury bed
ReplyDeleteI used to be able to find good advice from your blog posts. perth podiatrists
ReplyDeleteI found useful information on this topic as Now i'm focusing on a company project. Thank you posting relative information and its currently becoming easier to complete this project ppc company australia
ReplyDeleteYour website is really cool and this is a great inspiring article. Thank you so much. Skip Hire Ulverston
ReplyDeleteI’ve found every article I’ve read very helpful. Good one, and keep it going. Shipping To FBA Warehouse From China
ReplyDeletePretty good post. I have just stumbled upon your blog and enjoyed reading your blog posts very much. I am looking for new posts to get more precious info. Big thanks for the useful info. buy traffic
ReplyDeleteyou are in point of fact a excellent webmaster. The site loading pace is amazing. It seems that you are doing any distinctive trick. In addition, The contents are masterwork. you have done a magnificent task on this subject! 토토사이트
ReplyDeleteThis is a brilliant blog! I'm very happy with the comments!.. 먹튀검증사이트
ReplyDelete"Excellent post. I will be dealing with a few of these isswues as well..
ReplyDelete" 먹튀검증
토토사이트
ReplyDeleteNo matter what it is you are looking to move, we have the necessary tools to get the job done. Get your quotes now to see how we can help.
ReplyDeleteIn yoast seo be able unite the keyword you'd kind of thine submit yet web page in conformity with office because of into the iquire results.
토토커뮤니티
surprised why this coincidence didn’t came about earlier! I bookmarked it
ReplyDeleteI’ve found every article I’ve read very helpful. Good one, and keep it going.
배팅사이트
Guitar Pro 8.0.0 Crack is a software that can use to compose songs.
ReplyDeleteGreat post. I like your way to explain the java string with pipe character with not working. Java course in Indore is the right place to know more about java.
ReplyDeleteYour article is easy to read and understand. I would like to read more articles like this.
ReplyDeleteWhat Is the Software Testing Life Cycle? A Complete Guide
Thanks for the post.It was superb.
ReplyDeleteJava Classes in Nagpur
informative blog , keep posting java course in satara
ReplyDeleteJava is an object-oriented language, which means it is designed around the concept of objects. It promotes modularity, reusability, and ease of maintenance in software development.
ReplyDeletePreguntas Declaración Adulterio
Thanks for such informative and helpful blog.
ReplyDeleteJava Classes in Nagpur