class reqparam(querystring: string, val encode: string = "gbk") : hashmap<string, string>() {
init {
querystring.split("& ".toregex()).filter { it.contains("=") }.foreach {
val kv = it.split("(?".toregex())
put(kv[0], urldecoder.decode(kv[1], encode))
}
}
}
以上是kotlin代码,是将链接地址串的
querystring 拆分k=v形式,并提取值
fun main(args: array<string>) {
val domain = "fu.area.duxiu.com"
val subdomain = domain.replace(regex(""". ((\.\w ){2})"""), "$1")
println(subdomain)
}
取主域名
public static string cookiedomain(string domain) {
if (domain.matches("((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)")) {// 如果是ip地址,主域名就是ip地址
return domain;
}
return domain.substring(domain.indexof("."));// 写子域名,域名前边加上"."
}
判断ip
posted on 2016-07-26 18:04
simone 阅读(509)
评论(0) 编辑 收藏