请教,如何比较两个字符串的大小...

walter_lee68 2005-12-09 03:19:07
1.string h1="0401";
string h2="0451";
if (h1<h2)
{....}
这样比较会出错,如何比较字符串的大小

2.修改 DataSet 中的数据出错
DataSet DA_SPDJ=new DataSet();
SqlDataAdapter Dapt_SPDJ=new SqlDataAdapter("SELECT Field_F FROM SPDJ", Conn1);
Dapt_SPDJ.Fill(DA_SPDJ, "SPDJ");
DataTable TA_SPDJ=DA_SPDJ.Tables["SPDJ"];
TA_SPDJ.Rows(1)(Field_F)=1000; //修改,语句有错
...全文
464 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
aspczlover 2005-12-09
  • 打赏
  • 举报
回复
实现方法很多
实现了就好
赶快都发点分吧 哈哈
mbh0210 2005-12-09
  • 打赏
  • 举报
回复
有意思啊、。。。。。
cw888 2005-12-09
  • 打赏
  • 举报
回复
在“我的问题”
中点击有结帖即可
tianwai112 2005-12-09
  • 打赏
  • 举报
回复
TA_SPDJ.Rows[1][Field_F] = 1000;
tianwai112 2005-12-09
  • 打赏
  • 举报
回复
string.Compare(str1,str2);就可以了!!!!!!!!!!
bladeyf 2005-12-09
  • 打赏
  • 举报
回复
1.string h1="0401";
string h2="0451";
if (h1<h2)
{....}
这样比较会出错,如何比较字符串的大小


是不是比较两个字符串的长度啊,如果是的话,不是可以用
h1.length < h2.length 吗
如果是比较两个数的大小的话
不是可以用Int32.parse(h1) < Int32.parse(h2)吗
walter_lee68 2005-12-09
  • 打赏
  • 举报
回复
谢谢,搞定了,怎样给分你们?
Ivony 2005-12-09
  • 打赏
  • 举报
回复
这是VB还是C#?

1、if( int.Parse(h1) < int.Parse(h2) )
walter_lee68 2005-12-09
  • 打赏
  • 举报
回复
Field_F是数字来的,连编译说:"System.Data.DataTable.Rows"表示"属性",此处应为"方法"
LoveCherry 2005-12-09
  • 打赏
  • 举报
回复
TA_SPDJ.Rows[1]["Field_F"]=1000; //类型需要一致
winehero 2005-12-09
  • 打赏
  • 举报
回复
应该为:TA_SPDJ.Rows[行序号][字段序号] = 1000
walter_lee68 2005-12-09
  • 打赏
  • 举报
回复
请问第二个问题,怎样
JzeroBiao 2005-12-09
  • 打赏
  • 举报
回复
2.是唔是数字型来的?
winehero 2005-12-09
  • 打赏
  • 举报
回复
1)使用String对象的CompareTo方法:
private static string CompareStrings( string str1, string str2 ) {

// compare the values, using the CompareTo method on the first string
int cmpVal = str1.CompareTo(str2);

if (cmpVal == 0) // the values are the same
return "The strings have the same value!";

else if (cmpVal > 0) // the first value is greater than the second value
return "The first string is greater than the second string!";

else // the second string is greater than the first string
return "The second string is greater than the first string!";
}
}

110,555

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧