常量字符串与StringBuffer的联合(Concatenation of constant strings VS StringBuffer)
你可以给出什么论据,以便使用更好,更快,更正确的一个或另一个变体。
第一个变体:
StringBuffer sql = new StringBuffer("SELECT DISTINCT f.ID ") .append("FROM FIRST_TABLE F ") .append("LEFT JOIN SECOND_TABLE s ON f.ID = s.F_ID ") .append("WHERE ") .append("F.BOOL = 1 ") .append("AND S.DATE IS NOT NULL ") .append("AND S.CLOSED = 0 ");
第二个变体:
String sql = "SELECT DISTINCT f.ID " + "FROM FIRST_TABLE F " + "LEFT JOIN SECOND_TABLE s ON f.ID = s.F_ID " + "WHERE " "F.BOOL = 1 " + "AND S.DATE IS NOT NULL " + "AND S.CLOSED = 0";
*注意: Class String和Class StringBuffer 。
What arguments can You give for the use one or another variant that is better, faster, more correct.
First variant:
StringBuffer sql = new StringBuffer("SELECT DISTINCT f.ID ") .append("FROM FIRST_TABLE F ") .append("LEFT JOIN SECOND_TABLE s ON f.ID = s.F_ID ") .append("WHERE ") .append("F.BOOL = 1 ") .append("AND S.DATE IS NOT NULL ") .append("AND S.CLOSED = 0 ");
Second variant:
String sql = "SELECT DISTINCT f.ID " + "FROM FIRST_TABLE F " + "LEFT JOIN SECOND_TABLE s ON f.ID = s.F_ID " + "WHERE " "F.BOOL = 1 " + "AND S.DATE IS NOT NULL " + "AND S.CLOSED = 0";
*for note: Class String and Class StringBuffer.
原文:https://stackoverflow.com/questions/13530294
更新时间:2023-09-20 20:09
最满意答案
使用
file_get_contents()
将其读取为字符串使用gzuncompress()
对其进行解压缩,并使用simplexml_load_string()
将XML加载为XML。Read it to a string using
file_get_contents()
decompress it usinggzuncompress()
and load string as XML usingsimplexml_load_string()
.
相关问答
更多-
根据http://php.net/manual/en/simplexmlelement.construct.php我调整了这样的代码: xpath('//metadata/page/filename[.="services.php"]/parent::*'); $res ...
-
使用你在xml加载器中的url,我得到:
-
去掉 从文件的末尾。 没有开始标记
,有一个格式声明,不需要关闭。 Remove from the end of file. There is no opening tag, there is a declaration of format which does not require closing. -
替换用simplexml_load_file()加载的xml中的文本?(Replace text in xml loaded with simplexml_load_file()?)[2024-03-24]
如果您只想重命名和 标签,我建议您使用最简单的解决方案,即使用str_replace替换文本。 $xml_external_path = 'http://external-site.com/original.xml'; $xml = simplexml_load_file($xml_external_path); $searches = [' ']; $replacement ...', ' ', '', ' -
$a = simplexml_load_string($somestring); if($a===FALSE) { echo 'No Stats'; } else { echo "Valid XML found... processing."; } 馅饼简单。 $a = simplexml_load_string($somestring); if($a===FALSE) { echo 'No Stats'; } else { echo "Valid XML found... pr ...
-
使用simplexml_load_file()加载gzipped XML文件(Load gzipped XML file with simplexml_load_file())[2023-04-11]
使用file_get_contents()将其读取为字符串使用gzuncompress()对其进行解压缩,并使用simplexml_load_string()将XML加载为XML。 Read it to a string using file_get_contents() decompress it using gzuncompress() and load string as XML using simplexml_load_string(). -
children($ns,true) as $i) { echo $i->country; echo $i->date; echo $i->value; } ?> http://php.net/manual/en/simplexmlelement.children.php (参见:示例#2使用命名空间)该问题不是URL中的&符号。 相反,问题是weather.gov似乎阻止了这些类型的请求。 他们不允许没有使用useragent的用户。 解决这个问题的最快方法是在PHP中设置UserAgent,您可以将此代码放在xml调用之上: ini_set('user_agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0) Gecko/20100101 Firefox/9.0'); 但是,我建议使用CURL而不是simplexml_load_file,因为simpl ...
PHP:如何使用simplexml_load_file()var(PHP: How to get
working in a simplexml_load_file() var)[2022-09-30]两种方法使它工作。 正确的那一个 不要存放那些。 存储真实的实际换行符,例如Line 1. Line 2. 然后使用nl2br()用HTML标记替换换行符。 这假设您的描述通常不包含标记。 如果是,请使用另一个答案中提出的CDATA部分。 另一个 $descText = strip_tags($xml->aboutModule->chocolaterie->desc->asXML(), '
'); Two ways to make it ...无需同时执行simplexml_load_file 和创建新的SimpleXML对象。 simplexml_load_file已将XML 文件解释为对象。 (请记住,它不接受XML字符串) $movies = simplexml_load_file('test.xml'); 或者,您可以直接将XML 字符串加载到SimpleXML对象中。 $movies = new SimpleXMLElement(file_get_contents('test.xml')); 上述任何一种方法都可用于执行以下操作: ...相关文章
更多- Java StringBuffer和StringBuilder类
- StringBuffer 和StringBuilder的问题?难解
- Java 中String , StringBuffer 和StringBuilder
- 字符串应用之字符串编码转换
- java字符串内容的修改?
- Python 字符串操作
- java字符串解析
- mysql截取字符串
- shell脚本的字符串截取
- Lua 字符串操作
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。