我有一个字符串数组,它可能包含一个在字符串中带有文本"mytext"的元素.例如:
mystringarray
{
[0] => "hello world";
[1] => "some of mytext";
}
Run Code Online (Sandbox Code Playgroud)
我也有一个没有mytext文本的数组.
mystringarray
{
[0] => "hello world";
[1] => "some of notmy";
}
Run Code Online (Sandbox Code Playgroud)
我的问题是当我使用时:
string mytextdata = mystringarray.Single<string>(t => t.Contains("mytext")).ToString();
Run Code Online (Sandbox Code Playgroud)
我得到第二个数组的异常,因为它找不到与表达式匹配的元素.
有没有一种快速的方法我可以编辑这一行,如果没有找到任何内容就不会抛出异常,而只是忽略?我有很多这些行,我不想在if语句中包含每一行.
如果问题不明确,请道歉.
在调查某些问题时,我发现原因是看似相同的输入数据的字符串[]的意外不同转换.也就是说,在下面的代码中,两个命令都返回相同的两个项File1.txt和File2.txt.但转换为string []会产生不同的结果,请参阅注释.
任何想法为什么呢?这可能是一个错误.如果有人也这么认为,我会提交.但是,了解正在发生的事情并避免陷阱就好了.
# *** WARNING
# *** Make sure you do not have anything in C:\TEMP\Test
# *** The code creates C:\TEMP\Test with File1.txt, File2.txt
# Make C:\TEMP\Test and two test files
$null = mkdir C:\TEMP\Test -Force
1 | Set-Content C:\TEMP\Test\File1.txt
1 | Set-Content C:\TEMP\Test\File2.txt
# This gets just file names
[string[]](Get-ChildItem C:\TEMP\Test)
# This gets full file paths
[string[]](Get-ChildItem C:\TEMP\Test -Include *)
# Output:
# File1.txt
# File2.txt
# C:\TEMP\Test\File1.txt
# C:\TEMP\Test\File2.txt
Run Code Online (Sandbox Code Playgroud) 我正在制作这样的http get请求:
try {
HttpClient client = new DefaultHttpClient();
String getURL = "http://busspur02.aseag.de/bs.exe?SID=5FC39&ScreenX=1440&ScreenY=900&CMD=CR&Karten=true&DatumT="+day+"&DatumM="+month+"&DatumJ="+year+"&ZeitH="+hour+"&ZeitM="+min+"&Intervall=60&Suchen=(S)uchen>0=Aachen&T0=H&HT0="+start_from+">1=Aachen&T0=H&HT1="+destination+"";
HttpGet get = new HttpGet(getURL);
HttpResponse responseGet = client.execute(get);
HttpEntity resEntityGet = responseGet.getEntity();
if (resEntityGet != null) {
//do something with the response
Log.i("GET RESPONSE",EntityUtils.toString(resEntityGet));
}
...
} catch (...) {
...
}
Run Code Online (Sandbox Code Playgroud)
一切运作良好......唯一的问题是:Log.i的输出是截止的...这不是完整的html页面.如果我在浏览器中发出相同的请求,我会得到3倍的输出,而不是在模拟器中发出请求并使用上面的代码....出了什么问题?
错误:
04-30 14:01:01.287: WARN/System.err(1088): java.lang.IllegalStateException: Content has been consumed
04-30 14:01:01.297: WARN/System.err(1088): at org.apache.http.entity.BasicHttpEntity.getContent(BasicHttpEntity.java:84)
04-30 14:01:01.297: WARN/System.err(1088): at org.apache.http.conn.BasicManagedEntity.getContent(BasicManagedEntity.java:100)
04-30 14:01:01.307: WARN/System.err(1088): at org.apache.http.util.EntityUtils.toString(EntityUtils.java:112)
04-30 14:01:01.307: WARN/System.err(1088): at org.apache.http.util.EntityUtils.toString(EntityUtils.java:146)
04-30 14:01:01.307: WARN/System.err(1088): at …Run Code Online (Sandbox Code Playgroud) 在窗口形式中,我做了一个按钮,我试图将它发送F1到特定窗口(例如FireFox,我的电脑等......)
我的问题是:
我使用以下内容以希腊语输出一个月的全名.
setlocale(LC_TIME, 'el_GR');
strftime("%B");
Run Code Online (Sandbox Code Playgroud)
这是有效的,除了输出字符串是ISO-8859-7(希腊代码页),这是一个问题,因为我需要一个UTF-8字符串.我可以把它通过iconv转换它,但我想知道是否有办法做到这一点,而无需借助额外的功能.
在这种情况下,你能以某种方式告诉strftime输出UTF-8字符串吗?
我想从我的 data/data/com.apps.myapp/images 文件夹中检索图像并将其显示在 ImageView 中。有什么线索吗?
我们刚开始使用scrum进行项目管理.我们是一个非常小的团队(2个开发人员,1个UI/Web-deisgner),我们一次有很多正在运行的项目.
如何在scrum模型中同时运行多个项目?大多数时候我们有一个主要项目和一些小项目.如何有效地组合多个冲刺?
编辑:不要修复scrum.我们是一个小型结构,非常灵活.Scrum只是我的出发点.如果你有其他系统对你或你的小团队有用,我完全愿意接受任何形式的输入.
我提出一个问题,将任何数字表示为四个素数的总和.
条件:
我做了什么 :
使用Eratosthenes的筛子,我计算了所有素数,直到指定的数字.
查找了一个名为Goldbach猜想的概念,它将偶数表示为两个素数的总和.
但是,我被困在那之外.任何人都可以帮我解决一下你可能采取的方法吗?
Eratosthenes的筛子花了两秒钟来计算高达100,000的素数.
我是.NET平台的新手.目前我正在学习ASP.NET MVC.
我想从我的程序发送一封电子邮件,我有以下代码:
public void sendVerrificationEmail()
{
//create the mail message
MailMessage mail = new MailMessage();
//set the addresses
mail.From = new MailAddress("");
mail.To.Add("");
//set the content
mail.Subject = "This is an email";
mail.Body = "this is a sample body with html in it. <b>This is bold</b> <font color=#336699>This is blue</font>";
mail.IsBodyHtml = true;
//send the message
SmtpClient smtp = new SmtpClient("127.0.0.1");
smtp.Send(mail);
}
Run Code Online (Sandbox Code Playgroud)
现在,当我执行此代码时,我将得到以下异常:
System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:25
Run Code Online (Sandbox Code Playgroud)
现在我对IIS管理器和其他东西非常陌生.所以那里可能有些不对劲. …
我知道这个.
从C++调用C函数:
如果我的应用程序是在C++中,我不得不从用C编写的库调用函数.那么我会使用
//main.cpp
extern "C" void C_library_function(int x, int y);//prototype
C_library_function(2,4);// directly using it.
Run Code Online (Sandbox Code Playgroud)
这不会破坏名称C_library_function,链接器会在其输入*.lib文件中找到相同的名称,问题就解决了.
从C ???调用C++函数
但是在这里我扩展了一个用C语言编写的大型应用程序,我需要使用一个用C++编写的库.C++的名称错误导致了麻烦.Linker抱怨未解决的符号.好吧,我不能在我的C项目中使用C++编译器,因为这会破坏很多其他东西.出路是什么?
顺便说一句,我正在使用MSVC