private String removeNonDigits(final String value) {
if(value == null || value.isEmpty()){
return "";
}
return value.replaceAll("[^0-9]+", "");
}
Run Code Online (Sandbox Code Playgroud)
有更好的方法吗?Apache的StringUtils有类似的方法吗?
在C#中,我可以将隐式运算符添加到类中,如下所示:
public class MyClass
{
private int data;
public static implicit operator MyClass(int i)
{
return new MyClass { data = i };
}
public static implicit operator MyClass(string s)
{
int result;
if (int.TryParse(s, out result))
{
return new MyClass { data = result };
}
else
{
return new MyClass { data = 999 };
}
}
public override string ToString()
{
return data.ToString();
}
}
Run Code Online (Sandbox Code Playgroud)
然后我可以传递任何期望MyClass对象为字符串或int的函数.例如
public static string Get(MyClass c)
{
return c.ToString();
}
static void …Run Code Online (Sandbox Code Playgroud) 我有一个int类型的数组
矩阵[][]
它的值为0和1
000000000
101010111
000010100
110011001
Run Code Online (Sandbox Code Playgroud)
这些值与上述不同,但这是一个随机的例子.
我需要做的是,
当column = 0和row = 0时,循环遍历第一行,将row添加到第一行
如果找到一个,则将其添加到变量中
当我到达行的末尾时,我需要沿着colum 0 row = 0将1添加到列以获取循环
那么我需要检查我一直在添加的和变量是%2 = 0
然后我需要检查第1行第1列
并重复所有
我遇到的问题是确定我何时到达行的末尾,这是如何计算的?
for(int row = 0; row < matrix.length; row++){
if(matrix[columns][row] == 1){
sum ++;
if(i am at the end of the row){
//continue with other steps here
Run Code Online (Sandbox Code Playgroud) 我一直在尝试在PDF应用程序中执行搜索功能.我在iphone参考库中阅读了Quartz 2d指南.关于"pdf运营商"的说法如此之多.通过使用它们来完成所有操作,通过使用回调来完成它们.
有关pdf运算符的信息,我们应该阅读adobe的pdf参考.但它非常广阔.任何人都可以让我知道这些操作符是什么(或者如何在研究它们时得到一个想法)以及我在"搜索pdf中的字符串功能"中需要哪些操作符?
在Django管理员中,用户可以设置限制更改列表中显示的行的过滤器.如何获取QuerySet实例,其中过滤器设置为查询字符串定义的?例如,如果我通过?start_date_gte = 2009-11-06,Django管理员将在某处应用qs.filter(start_date__gte ...).我怎样才能访问这样的QuerySet?
我需要这个,因为很明显我不想重写那些采用这些GET参数的代码和相应的filter()sa QuerySet.
我想基于后台线程实现可中断的任务.实现该TTask.Stop方法的最简洁方法是什么?我怎样才能中止后台线程?
在线程上下文中执行的代码使用匿名方法传递给任务,并且可以包含阻塞调用,因此我不能依赖于Terminated从代码中定期检查标志的事实.
感谢您的任何意见.
在重要的情况下使用D2010(某些事情TThread似乎已经改变)
我有一个带有DataGridView的表单,我想使用DataSet将XML文件中的数据加载到Grid中.我创建一个DataSet,将XML加载到DataSet中,然后将DataSet分配给Grid的DataSource属性:
private void formAccountHistory_Load(object sender, EventArgs e)
{
// Load the DataSet that represents the offline version of the database.
AccountHistoryDS = new DataSet("TicketAccountHistory");
AccountHistoryDS.ReadXmlSchema("TicketsAccountHistory.xsd");
AccountHistoryDS.ReadXml("TicketsAccountHistory.xml", XmlReadMode.Auto);
AccountHistoryDS.Locale = System.Globalization.CultureInfo.CurrentUICulture;
dataGridViewStatement.AutoGenerateColumns = false;
dataGridViewStatement.DataSource = AccountHistoryDS;
dataGridViewStatement.DataMember = "Line";
}
Run Code Online (Sandbox Code Playgroud)
但是,数据不会显示在网格中.我在XML文件中有8行,而Grid创建了8行,但它们都是空白的.当我调试代码时,我可以看到DataSet中的数据,所以它似乎正确加载到那一点,只是没有在Grid中显示它.我使用的XML文件如下所示 - 它格式正确,并根据其架构进行验证:
<?xml version="1.0" standalone="yes"?>
<TicketsAccountHistory>
<Line>
<colID>03/09</colID>
<colStartEnd>14/01/2009-20/01/2009</colStartEnd>
<colDate>14/01/2009</colDate>
<colType>Period 03/09 - opening balance</colType>
<colDR></colDR>
<colCR></colCR>
<colBalance>0.00</colBalance>
</Line>
<Line>
<colID>03/09</colID>
<colStartEnd>14/01/2009-20/01/2009</colStartEnd>
<colDate>20/01/2009</colDate>
<colType>Sales Invoice (Ref: MRO-S-03/09)</colType>
<colDR>1000</colDR>
<colCR></colCR>
<colBalance>1000.00</colBalance>
</Line>
<Line>
<colID>03/09</colID>
<colStartEnd>14/01/2009-20/01/2009</colStartEnd>
<colDate>20/01/2009</colDate>
<colType>Commission Invoice (Ref: MRO-C-03/09)</colType> …Run Code Online (Sandbox Code Playgroud) 我需要选择Windows自动化脚本语言.你推荐哪一个; AutoIt,AutoHotkey还是其他?
我读过" An AutoIt/AutoHotkey比较 ".有趣的历史,但没有推荐.搜索谷歌大约有312,000次点击,而AutoHotkey Windows对于482k AutoIt Windows.在Stack Overflow上有15个问题标记为autoit vs 18 autohotkey.
我对程序员的看法很感兴趣.您认为哪一个更易于使用,更易于部署且功能更强大?我已经将AutoHotkey用于个人用途,所以我最初的偏好就是这个.