我试图获得匹配的最后结果,而不必循环通过.find()
这是我的代码:
String in = "num 123 num 1 num 698 num 19238 num 2134";
Pattern p = Pattern.compile("num '([0-9]+) ");
Matcher m = p.matcher(in);
if (m.find()) {
in = m.group(1);
}
Run Code Online (Sandbox Code Playgroud)
这将给我第一个结果.我怎样才能找到最后一场比赛,而不是通过潜在的巨大名单?
我正在关注此链接中的示例并创建了一个类,如下所示
public class aChartExample {
public Intent execute(Context context) {
int[] colors = new int[] { Color.RED, Color.YELLOW, Color.BLUE };
DefaultRenderer renderer = buildCategoryRenderer(colors);
CategorySeries categorySeries = new CategorySeries("Vehicles Chart");
categorySeries.add("cars ", 30);
categorySeries.add("trucks", 20);
categorySeries.add("bikes ", 60);
return ChartFactory.getPieChartIntent(context, categorySeries, renderer, null);
}
protected DefaultRenderer buildCategoryRenderer(int[] colors) {
DefaultRenderer renderer = new DefaultRenderer();
for (int color : colors) {
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(color);
renderer.addSeriesRenderer(r);
}
return renderer;
}
}
Run Code Online (Sandbox Code Playgroud)
当我的应用程序在onCreate中的启动活动开始时,我正在调用它.
@Override
protected void onCreate(Bundle savedInstanceState) …Run Code Online (Sandbox Code Playgroud) 如果我有一堆文本,请说HTML,但它不一定是.
</TD>
<TD CLASS='statusEven'><TABLE BORDER=0 WIDTH='100%' CELLSPACING=0 CELLPADDING=0><TR><TD ALIGN=LEFT><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>
<TR>
<TD ALIGN=LEFT valign=center CLASS='statusEven'><A HREF='extinfo.cgi? type=2&host=localhost&service=Current+Load'>Current Load</A></TD></TR>
</TABLE>
</TD>
<TD ALIGN=RIGHT CLASS='statusEven'>
<TABLE BORDER=0 cellspacing=0 cellpadding=0>
<TR>
</TR>
</TABLE>
</TD>
</TR></TABLE></TD>
<TD CLASS='statusOK'>OK</TD>
<TD CLASS='statusEven' nowrap>08-04-2011 22:07:00</TD>
<TD CLASS='statusEven' nowrap>28d 13h 18m 11s</TD>
<TD CLASS='statusEven'>1/1</TD>
<TD CLASS='statusEven' valign='center'>OK - load average: 0.01, 0.04, 0.05 </TD>
Run Code Online (Sandbox Code Playgroud)
我想抓住2个标记之间的所有内容,结果可能是多行,我该怎么做?
这是我到目前为止所拥有的......
Pattern p = Pattern.compile("extinfo(.*)load average");
Matcher m = p.matcher(this.resultHTML);
if(m.find())
{
return m.group(1);
}
Run Code Online (Sandbox Code Playgroud) 我在这里遵循一些指示:http://saigeethamn.blogspot.com/2010/04/custom-listview-android-developer.html
我正在关注的示例显示全屏列表.这就是我想要我做的事情.我究竟做错了什么?
示例结果:
我的结果:

我遵循的示例使用了2 xml布局.1页面.1列表.
这页纸:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000fff"
android:layout_weight="2"
android:drawSelectorOnTop="false">
</ListView>
<TextView android:id="@id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFff00"
android:text="No data"
/>
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
这是列表的xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView android:id="@+id/tvAccountName"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#FFFF00"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<TextView android:id="@+id/tvAccountType"
android:typeface="sans"
android:textSize="14sp"
android:textStyle="italic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/tvAccountBalance"
android:textSize="12sp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="fill_parent"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是清单中的条目:
<activity android:name=".listAccountsPage"
android:label="@string/app_name"
>
<intent-filter>
<action android:name="com.ourcreditunion.ourcumobile.LISTACCOUNTS" />
<category …Run Code Online (Sandbox Code Playgroud) 此正则表达式未找到任何匹配项.在其他语言中我运行它,效果很好.在像rubular.com这样的在线正则表达式测试人员中,它非常有用.
在java中,它不起作用.
有什么不同的java正则表达式,他们打破这样的事情?
为什么不起作用?此外,我怎么能在将来弄清楚他们为什么不匹配?
样本数据
<link>http://www.wunderground.com/US/MI/Milan.html</link>
<description><![CDATA[Temperature: 89.4°F | Humidity: 62% | Pressure: 29.65in (Steady) | Conditions: Clear | Wind Direction: NW | Wind Speed: 1.6mph<img src="http://server.as5000.com/AS5000/adserver/image?ID=WUND-00070&C=0" width="0" height="0" border="0"/>]]>
</description>
Run Code Online (Sandbox Code Playgroud)
和代码
protected void parseTemperature()
{
Pattern p = Pattern.compile("/Temperature: ([0-9.]+)°/");
Matcher m = p.matcher(this.xml);
if (m.find())
{
this.temperature = Double.valueOf(m.group(1));
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个ArrayList.
每个元素都是HashMap我的值的查找.
其中一个值是数字.
我正在使用Collections.sort()alpha排序.但数字正在进行alpha排序,而不是数字排序.
protected ArrayList<HashMap<String, String>> myAccountList;
String Name = myAccountList.get(i).get("accountName");
Double balance = Double.valueOf(myAccountList.get("accountBalance")); //is a number stored as a string
Run Code Online (Sandbox Code Playgroud)
所以我对accountName的工作正常.
Collections.sort(myAccountList, new Comparator(){
public int compare(Object o1, Object o2) {
HashMap<String,String> old1 = (HashMap<String, String>) o1;
HashMap<String,String> old2 = (HashMap<String, String>) o2;
return old1.get("accountName").compareToIgnoreCase(old2.get("accountName"));
}
});
Run Code Online (Sandbox Code Playgroud)
如何将字段accountBalance排序为数字?我怀疑这很重要,但我正在编写一个Android应用程序.