gpt4 book ai didi

c# - 子字符串和索引

转载 作者:行者123 更新时间:2023-11-30 17:12:50 24 4
gpt4 key购买 nike

我正在使用 J2me、ASP 和 WML 创建一个移动网站。

我从数据库中读取并创建了一个字符串,如下所示,以便稍后调用它。

                string id = reader[0].ToString();
string name = reader[1].ToString();
Response.Write("#" + name + id);

在J2me中我记得是

stringItem3.setText("Welcome  "+result.substring(result.indexOf("#")+1)
+ "ID " + result.substring(result.indexOf("#")+2));

结果并不如我所愿,我尝试对语法进行大量更改,但没有成功。

结果总是显示为

enter image description here

虽然我真正想展示的是类似

Welcome  (name)  ID : (id)
or
Welcome Arin ID : 20111

获得正确结果的最佳方法是什么?

我可以稍后将 id 值保存在 J2me 中的字符串中以供以后使用(是/否)吗?


我改了字符串(解决了)

string id = reader[0].ToString();
string name = reader[1].ToString();
Response.Write("*"+ id + "#" + name);

获取信息时

stringItem3.setText("Welcome  "+result.substring(result.indexOf("#")+1)
+ "ID " + result.substring(result.indexOf("*")+1,result.indexOf("#")));

result.substring(result.indexOf("*")+1,result.indexOf("#")));

意思是获取“*”和“#”之间的字符

现在结果很好,如下图。

enter image description here

最佳答案

您要保存的字符串类似于 #Arin20111 , 所以 indexOf("#")+2# 之后的第二个nd 字符.

所以 result.substring(result.indexOf("#")+1)# 之后的完整 字符串,即名称​​和 ID。和 result.substring(result.indexOf("#")+1)是相同的字符串,除了 A在一开始。

如果您知道名称永远不会包含 # ,您可以将字符串存储为 #Arin#20111 .然后名称就是<sup>st</sup>之后的一切# and before the 2<sup>nd</sup> # , and the ID is everything after the 2<sup>nd</sup> #`.

关于c# - 子字符串和索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10363818/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com