程序设计

专业和发烧友程序员的问答

10
确定PHP中是否存在数组键的更快,更好的方法是什么?
考虑这两个例子... $key = 'jim'; // example 1 if (isset($array[$key])) { // ... } // example 2 if (array_key_exists($key, $array)) { // ... } 我有兴趣知道这些方法是否更好。我一直使用第一个示例,但是看到很多人在此站点上使用第二个示例。 那么,哪个更好?快点?意图更清晰?
157 php  performance 

6
如何使Twitter Bootstrap工具提示有多行?
我目前正在使用以下功能来创建将通过Bootstrap的工具提示插件显示的文本。多行工具提示如何只能使用<br>而不能使用\n?我希望链接的标题属性中没有任何HTML。 什么有效 def tooltip(object) tooltip = "" object.each do |user| tooltip += "#{user.identifier}" + "<br>" end return tooltip end 我想要的是 def tooltip(object) tooltip = "" object.each do |user| tooltip += "#{user.identifier}" + "\n" end return tooltip end

19
PHP将XML转换为JSON
我试图将xml中的xml转换为json。如果我使用简单的xml和json_encode进行简单的转换,则xml中的任何属性都不会显示。 $xml = simplexml_load_file("states.xml"); echo json_encode($xml); 所以我试图像这样手动解析它。 foreach($xml->children() as $state) { $states[]= array('state' => $state->name); } echo json_encode($states); 状态的输出{"state":{"0":"Alabama"}}不是{"state":"Alabama"} 我究竟做错了什么? XML: <?xml version="1.0" ?> <states> <state id="AL"> <name>Alabama</name> </state> <state id="AK"> <name>Alaska</name> </state> </states> 输出: [{"state":{"0":"Alabama"}},{"state":{"0":"Alaska"} var dump: object(SimpleXMLElement)#1 (1) { ["state"]=> array(2) { [0]=> object(SimpleXMLElement)#3 (2) { ["@attributes"]=> array(1) …
157 php  xml  json 

18
CryptographicException'密钥集不存在',但仅通过WCF
我有一些代码可以调用使用X.509认证保护的第三方Web服务。 如果我直接调用代码(使用单元测试),它将正常工作。 部署后,将通过WCF服务调用此代码。我添加了另一个调用WCF服务的单元测试,但是当我在第三方Web服务上调用方法时,此失败并CryptographicException显示消息"Keyset does not exist"。 我认为这是因为我的WCF服务将尝试使用与我自己不同的用户来调用第三方Web服务。 任何人都可以在这个问题上提出更多的建议吗?
157 .net  wcf  x509 


28
ScrollView中的ListView在Android上不滚动
我有一个滚动的麻烦ListView内ScrollView。我有一个Activity,在顶部具有一些EditTexts,然后是一个带有两个选项卡的选项卡主机,每个选项卡具有一个ListView。当EditText视图成为焦点时,出现软键盘,并且当我有ScrollView时,内容可以滚动。但是问题来了,当ListViews中有更多项(选项卡中的项)时,即使有更多项,我也无法滚动ListView。 以下是布局XML: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="?backgroundImage" android:orientation="vertical"> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="50dip" android:layout_alignParentBottom="true" android:layout_margin="10dip" android:id="@+id/buttons"> <Button android:text="Save" android:layout_margin="2dip" android:textSize="20dip" android:id="@+id/btnSaveorUpdate" android:layout_height="wrap_content" android:layout_width="145dip"></Button> <Button android:text="Cancel" android:layout_margin="2dip" android:textSize="20dip" android:id="@+id/btnCancelorDelete" android:layout_height="wrap_content" android:layout_width="145dip"></Button> </LinearLayout> <ScrollView android:layout_above="@id/buttons" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillViewport="true" android:layout_margin="10dip"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_margin="10dip"> <TextView android:text="Bill details" android:textColor="?textColorDark" android:layout_alignParentTop="true" android:id="@+id/txtEnterDetails" …

14
在圆ci中找不到com.android.tools.build:gradle:3.0.0-alpha1
我将gradle插件更新为最新版本:com.android.tools.build:gradle:3.0.0-alpha1 并发生了此错误: export TERM="dumb" if [ -e ./gradlew ]; then ./gradlew test;else gradle test;fi FAILURE: Build failed with an exception. What went wrong: A problem occurred configuring root project 'Android-app'. Could not resolve all dependencies for configuration ':classpath'. Could not find com.android.tools.build:gradle:3.0.0-alpha1. Searched in the following locations: https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0-alpha1/gradle-3.0.0-alpha1.pom https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0-alpha1/gradle-3.0.0-alpha1.jar Required …


27
如何优雅地检查数字是否在范围内?
如何使用C#和.NET 3.5 / 4优雅地做到这一点? 例如,数字可以在1到100之间。 我知道一个简单的方法就足够了。但是这个问题的关键词是优雅。这是给我的玩具项目而不是生产项目。 这个问题不是关于速度,而是关于代码美。停止谈论效率之类的话题;记得你在向合唱团宣道。
157 c#  numbers  int 


7
如何使用C#查找和替换文件中的文本
到目前为止我的代码 StreamReader reading = File.OpenText("test.txt"); string str; while ((str = reading.ReadLine())!=null) { if (str.Contains("some text")) { StreamWriter write = new StreamWriter("test.txt"); } } 我知道如何查找文本,但是我不知道如何用自己的文本替换文件中的文本。


3
形状xml中的边框
我正在尝试使一个可绘制的按钮使用。我希望它具有这种颜色,并带有2px的边框。 一切正常,除非我无法显示边框... <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <gradient android:startColor="@color/bar_clicked_dark" android:endColor="@color/bar_clicked_light" android:angle="90"/> <corners android:bottomLeftRadius="0dp" android:topLeftRadius="15dp" android:bottomRightRadius="15dp" android:topRightRadius="0dp" /> <stroke android:width="2dp" color="#ff00ffff" /> </shape>


9
MySQL-在WHERE子句中使用COUNT(*)
我正在尝试在MySQL中完成以下操作(请参见pseudo代码) SELECT DISTINCT gid FROM `gd` WHERE COUNT(*) > 10 ORDER BY lastupdated DESC 有没有一种方法可以在WHERE子句中不使用(SELECT ...),因为这似乎浪费资源。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.