Formatting IP:Port string to

前端 未结 6 693
遇见更好的自我
遇见更好的自我 2021-01-23 07:13

I\'m trying to make a little chat program for experimentation, but seeing as I\'m not the best Java programmer, I don\'t know how to separate a port from an IP where they are bo

6条回答
  •  日久生厌
    2021-01-23 07:59

    Use String.split
    IP = splittedIP[0], Port = splittedIP[1] in String
    you will need Integer.parseInt to get the integer value of port

    String[] ipSplit = "127.0.0.1:80".split(":");
    String ip = ipSplit[0];
    int port = Integer.parseInt(ipSplit[1]);
    

提交回复
热议问题