Java splits an IP address into an array

Source: Internet
Author: User

This problem was not noticed before, it seems to remember to split the regular string, but not like the IP is "." To divide the regular character, but the other.

Today, the use of similar functions, code written well did not test, directly upload the server, but it will be error, after looking at the log is the IP partition part of the code in addition to the problem, and then find information on the Internet, find the information that the method is my current error this method, no language people out a small meeting, want to be able to use Then the method was found on the net, and then the partition identifier in the regular expression was transferred to the ".", and did not expect to split it,

But then notice that people's string delimiter is not the same, holding the heart to try, the word IP separator dot replace sing Woo it like the "\ \", and then debugging incredibly line,

Put the code below to take notes.


String ip= "160.18.214.211";
Ip=ip.replace (".", "\ \");
string[] Iparr = Ip.split ("[^\\d]+");

Java splits an IP address into an array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.