我从字符串中减去日期部分;有时最后会有一个额外的角色,如:
Mon, 1 Oct 2011 10:51:52 -0400%
有时,日期很好,不需要修剪:
Mon, 21 Oct 2011 10:51:52 -0400
如果角色确实存在,如何删除最后一个字符(本例中为%)?
答案 0 :(得分:1)
如果您知道角色,可以使用<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_of_my_dialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:orientation="vertical">
<!-- Here I'll have the checkbox -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test"
android:textColor="#ff0000" />
</LinearLayout>
。
REPLACE
如果您在附加字符之前的所有内容都有固定格式,则可以使用REPLACE(@input, '%', '')
查找最后一个&#39;:&#39;,然后获取第一个字符的CHARINDEX
直到已知的好字符(在你的情况下达到-0400):
SUBSTRING
返回:
DECLARE @Input VARCHAR(50) = 'Mon, 1 Oct 2011 10:51:52 -0400%'
SELECT SUBSTRING(@Input, 1, LEN(@Input) - CHARINDEX(':', REVERSE(@Input)) + 9)