我从数据库中获取数据,其中一列由带空格的值组成(例如:55 22 44 88 9997
)。
我想修剪空格以与我的数据进行比较。
我的值为string a="552244889997"
,我将此值与db中的值进行比较,
但在db中它由空格55 22 44 88 9997
组成。
请帮我修复asp dotnet背后的代码中的这个问题。
答案 0 :(得分:0)
string a = "55 22 44 88 9997";
a = a.Replace(" ", string.Empty);
答案 1 :(得分:0)
string a =" 55 22 44 88 9997&#34 ;; a = a.Replace("","");
从数据库获取数据并删除空格:
SqlConnection conn = new SqlConnection(connectionString);
DataTable dt = new DataTable();
string cmd = null;
cmd = "select col1 from table";
SqlDataAdapter adp = new SqlDataAdapter(cmd, conn);
conn.Open();
adp.Fill(dt);
conn.Dispose();
if (dt.Rows.Count > 0) {
string b = Strings.Replace(dt.Rows(0)("col1"), " ", "");
}