使用此代码,我得到此输出:
TreeSet<String> t=new TreeSet<String>();
t.add("test 15");
t.add("dfd 2");
t.add("ersfd 20");
t.add("asdt 10");
Iterator<String> it=t.iterator();
while(it.hasNext()){
System.out.println(it.next);
}
Run Code Online (Sandbox Code Playgroud)
我明白了:
asdt 10
dfd 2
ersfd 20
test 15
Run Code Online (Sandbox Code Playgroud)
如何根据数字,使用TreeSet获得此类订单?
dfd 2
asdt 10
test 15
ersfd 20
Run Code Online (Sandbox Code Playgroud) 我想使用 id 标签提取属性“value”的值。
我的代码:
<?php
$url = 'http://turni.tt-contact.com/Default.aspx';
$contents = htmlentities(file_get_contents($url));
echo $contents."\n"; //html
$dom = new DOMDocument;
$dom->validateOnParse = true;
$dom->loadHTML($contents);
$dom->preserveWhiteSpace = false;
$data = $dom->getElementById("__VIEWSTATE");
echo $data->nodeValue;
?>
Run Code Online (Sandbox Code Playgroud)
我想要属性“值”->“这个”:
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="THIS">
Run Code Online (Sandbox Code Playgroud)
但代码只返回 html 代码。
我需要改变什么?
也可以将其修改为:
$xpath = new DOMXpath($dom);
$data = $xpath->query('//input[@id="__VIEWSTATE"]');
$node = $data->item(0);
echo $node->getAttribute('value');
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Fatal error: Call to a member function getAttribute() on null
Run Code Online (Sandbox Code Playgroud) 我有一个像这样的字符串:
String a = "Barbara Liskov (born Barbara Jane Huberman on November 7, 1939"
+" in California) is a computer scientist.[2] She is currently the Ford"
+" Professor of Engineering in the MIT School of Engineering's electrical"
+" engineering and computer science department and an institute professor"
+" at the Massachusetts Institute of Technology.[3]";
Run Code Online (Sandbox Code Playgroud)
我想,以取代所有这些元素:[1],[2],[3],等等,用一个空格.
我尝试过:
if (a.matches("([){1}\\d(]){1}")) {
a = a.replace("");
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用!