你好我在徘徊如何在Java中复制一段字符串,直到找到一个字符/符号.在我的情况下,原始字符串是:"hello.1234"我只想要"hello",所以符号后面的所有东西.都被丢弃了.
任何的想法?非常感谢
编辑:
解决如下:
String partBeforeFullStop = input.split("\\.")[0];
Run Code Online (Sandbox Code Playgroud) 我有一个返回3个结果的聚合
{ "serverUsed" : "/127.0.0.1:27017" , "result" : [ { "_id" : "luke" , "times" : 56} , { "_id" : "albert" , "times" : 28} , { "_id" : "matt" , "times" : 28}] , "ok" : 1.0}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试迭代结果时,代码进入无限循环(无法理解为什么!!)
AggregationOutput output = coll.aggregate( match1, unwind, match2, group, sort, limit);
Iterable<DBObject> list= output.results();
while(list.iterator().hasNext()){
String id = (String) list.iterator().next().get("_id");
int times = Integer.parseInt(list.iterator().next().get("times").toString());
System.out.println("ID IS "+id+" time: "+times);
}
Run Code Online (Sandbox Code Playgroud)
输出也重复第一个结果:
ID IS luke time: 56
ID IS luke time: 56 …Run Code Online (Sandbox Code Playgroud) 我一直在寻找一种简单轻便的解决方案来检测移动设备并呈现适当的视图.
不幸的是,我的方法并没有取得多大成功.
<!-- MOBILE DETECTION SCRIPT-->
<script type="text/javascript">
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)) {
@ViewBag.IsMobile =true;
}
else{
@ViewBag.IsMobile = false;
}
</script>
<p>BOOLEAN VALUE IS : @ViewBag.IsMobile
</p>
@if (ViewBag.IsMobile == false)
{
<div id="container">
Run Code Online (Sandbox Code Playgroud)
无论我使用ViewBag或Session还是var,它都不适用于if-then-else逻辑.
请建议一些解决方案!
我试图渲染一个html表,其中包含从我的控制器填充的列表.这就是我在做的事情:
//Home Controller
app.controller("HomeController", function ($scope, $location, ExamService, AuthenticationService, $cookieStore) {
$scope.items = '[{"id":"1","title":"Test 1","description":"this is a description"}]';
});
Run Code Online (Sandbox Code Playgroud)
并在页面中:
<table class="table" ng-controller="HomeController">
<th>Id</th>
<th>Title</th>
<th>Description</th>
<tr ng-repeat="item in items">
<td>{{item.id}}</td>
<td>{{item.title}}</td>
<td>{{item.description}}</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
然而,这会生成一个包含109个tr节点的空白表...我做错了什么?请帮忙