AS3还可以通过CDATA标签声明多行字符串

本文介绍在ActionScript 3 (AS3) 中如何利用CDATA标签声明多行字符串的方法,并展示了如何保持字符串的原始格式,包括换行和空格。此外,还讨论了在XML设置为保留空白字符的情况下,避免错误的做法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在腾讯微博上发现这个,立马在博客做个记录。在AS3中,声明多行字符串(或叫做原样输出),可以这样做(注意:没有双引号):

private var myString:String = <![CDATA[第一行
第二行
第三行]]>;

为什么叫原样输出?因为我发现,字符串在 CDATA 标签里是什么样的,输出时就是什么样的。像 html 的 pre 标签一样。有换行就换行,每行前面有空格的,输出时就有空格。

我的理解:这其实就是 XML 特有的 CDATA 标签。在 CDATA 标签里,无论是什么字符,都不会经过转换,都是原样输出。类似的技巧还是有的,例如在 XML 里插入变量,在编译后会把变量值插入到对应位置:

private var myName:String = “Y.Boy“;
private var myXML:XML = <user><name>{MyName}</name><user>;
// 输出:<user><name>Y.Boy</name><user>

2011.3.11更新:

在这里(http://ticore.blogspot.com/2011/03/as3-multiline-cdata-string.html,需要翻墙)看到一些需要补充的内容:

另外假如 XML 设置为保留空白字符,这样的写法会出错:

XML.ignoreWhitespace = false;
var str:String = <![CDATA[
多行
字串]]>;
// TypeError: Error #1088: 文件中根元素之后的标签必须使用正确格式。

解決的方式很简单,用一个根标签包起来就行了(这相当于是使用一个XML对象包起来,然后默认调用 toString() 方法,把返回值赋给变量 str ):

XML.ignoreWhitespace = false;
var str:String = <><![CDATA[
多行
字串]]></>;

而且還能用來包覆多個 CDATA 區塊呢:

var str:String = <>
<![CDATA[字串1]]>
<![CDATA[字串2]]>
</>;
trace(str);

WITH product_aggregate AS ( SELECT T21.system_item_code AS system_item_code , T22.item_name AS item_name , T22.recommendation_sales_price AS recommendation_sales_price , T21.service_charge_type AS service_charge_type FROM( SELECT DISTINCT T11.system_item_code AS system_item_code , T11.service_charge_type AS service_charge_type FROM( SELECT T00.item_code AS item_code, T00.system_item_code AS system_item_code, T00.service_charge_type AS service_charge_type FROM m_ia_reserve_item T00 INNER JOIN m_ia_item_by_store_all T01 ON T01.pattern_type = T00.pattern_type AND T01.pattern_code = T00.pattern_code AND T01.version = &#39;1001_001&#39; AND T01.original_store_code = &#39;240600&#39; AND T01.system_item_code = T00.system_item_code WHERE T00.reserve_analysis_group_code = &#39;1&#39; AND T00.version = &#39;1001_001&#39; AND T00.apply_start_date <= CAST(&#39;20240315&#39; AS DATE) UNION ALL SELECT T10.item_code AS item_code, T10.system_item_code AS system_item_code, T10.service_charge_type AS service_charge_type, FROM m_ia_reserve_item_netgift T10 WHERE T10.version = &#39;2024_001&#39; AND T10.original_store_code = &#39;240600&#39; AND T10.reserve_analysis_group_code = &#39;1001&#39; ) T11 ) T21 INNER JOIN m_ia_item_by_store_all T22 ON T22.version = &#39;2024_001&#39; AND T22.original_store_code = &#39;240600&#39; AND T22.system_item_code = T21.system_item_code ) SELECT T21.item_code AS item_code, T21.system_item_code AS system_item_code, T20.item_name AS item_name, T20.recommendation_sales_price AS recommendation_sales_price, T20.service_charge_type AS service_charge_type, TO_CHAR(T21.analysis_date, &#39;YYYYMMDD&#39;) AS analysis_date, CASE WHEN T20.service_charge_type IN (&#39;1&#39;,&#39;2&#39;) THEN 0 ELSE T21.delivery_quantity END AS delivery_quantity, CASE WHEN T20.service_charge_type IN (&#39;1&#39;,&#39;2&#39;) THEN 0 ELSE T21.sales_quantity END AS sales_quantity, T21.delivery_result_flag AS delivery_result_flag, T21.sales_amount AS sales_amount FROM product_aggregate T20 INNER JOIN t_ia_reserve_item_aggregate T21 ON T21.system_item_code = T20.system_item_code AND T21.original_store_code = &#39;240600&#39; AND T21.reserve_analysis_group_code = &#39;1001&#39; AND T21.analysis_date <![CDATA[ <= ]]> CAST(#{targetPeriodEndDate} AS DATE) <if test="targetPeriodStartDate <= salesStartDate"> AND T21.analysis_date <![CDATA[ >= ]]> CAST(#{targetPeriodStartDate} AS DATE) </if> <if test="salesStartDate < targetPeriodStartDate"> AND T21.analysis_date <![CDATA[ >= ]]> CAST(#{salesStartDate} AS DATE) </if> ORDER BY T21.item_code, T21.system_item_code, T21.analysis_date 这段代码有错误吗
06-12
select wo.id, wo.work_order_no, wo.work_order_stauts, wo.curr_approver_code, wo.curr_approver_name, wo.create_time, wo.city_code, wo.city_name, wo.applicant_code, wo.applicant_name, wo.district_code, wo.district_name, wo.approver_desc, wo.annex_info, wo.curr_work_id, wo.work_id from t_process_work_order wo left join t_process_claim_user u on u.city_code = wo.city_code and wo.district_code = u.district_code and u.person_type = wo.curr_approver_code <where> <if test="id != null"> and wo.id = #{id} </if> <if test="workOrderNo != null and workOrderNo != &#39;&#39;"> and wo.work_order_no = #{workOrderNo} </if> <if test="status != null and status == 1"> and wo.work_order_stauts = 1 </if> <if test="status != null and status == 2"> and wo.work_order_stauts in (2,3) </if> <if test="workOrderStauts != null"> and wo.work_order_stauts = #{workOrderStauts} </if> <if test="currApproverCode != null and currApproverCode != &#39;&#39;"> and wo.curr_approver_code = #{currApproverCode} </if> <if test="currApproverName != null and currApproverName != &#39;&#39;"> and wo.curr_approver_name like concat(&#39;%&#39;,#{currApproverName},&#39;%&#39;) </if> <if test="endTime != null"> and wo.create_time <![CDATA[<=]]> #{endTime} </if> <if test="startTime != null"> and wo.create_time >= #{startTime} </if> <if test=&#39;areaLevel == "2"&#39;> and wo.city_code = #{areaCode} </if> <if test=&#39;areaLevel == "3"&#39;> and wo.district_code = #{areaCode} </if> <if test="cityCode != null and cityCode != &#39;&#39;"> and wo.city_code = #{cityCode} </if> <if test="cityName != null and cityName != &#39;&#39;"> and wo.city_name = #{cityName} </if> <if test="applicantCode != null and applicantCode != &#39;&#39;"> and wo.applicant_code = #{applicantCode} </if> <if test="applicantName != null and applicantName != &#39;&#39;"> and wo.applicant_name concat like concat(&#39;%&#39;,#{applicantName},&#39;%&#39;) </if> <if test="districtCode != null and districtCode != &#39;&#39;"> and wo.district_code = #{districtCode} </if> <if test="districtName != null and districtName != &#39;&#39;"> and wo.district_name like concat(&#39;%&#39;, #{districtName},&#39;%&#39;) </if> <if test="approverDesc != null and approverDesc != &#39;&#39;"> and wo.approver_desc = #{approverDesc} </if> <if test="annexInfo != null and annexInfo != &#39;&#39;"> and wo.annex_info = #{annexInfo} </if> <if test="currWorkId != null"> and wo.curr_work_id = #{currWorkId} </if> <if test="workId != null"> and wo.work_id = #{workId} </if> </where>帮我改一下,,现在会对应多个用户数据,但是我现在不需要展示多条,因为我只要用户的名字,把用户的名字通过逗号拼接成为 curr_approver_name
最新发布
07-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值