1、

<C#>

String.Format
将指定的 String 中的每个格式项替换为相应对象的值的文本等效项。
例子1:
int iVisit = 100;
string szName = "Jackfled";
Response.Write(String.Format("您的帐号是:{0} 。访问了 {1} 次.", szName, iVisit));

 

例子2:

c#把“23”格式成“000023”,用string.format,应该怎么写?

int i=23;
strNum=string.Format("{0:D6}", i); 

 

<java>

String.format()是根据一定的格式,将已经存在的字符串格式化
例如 System.out.println(String.format("今天的日期是:%tD", new java.util.Date()));
打印结果就是: 今天的日期是:03/22/08
该方法的第一个参数,就是格式,具体的格式说明,参考http://hi.baidu.com/zhangjianshe/blog/item/c21604b36b1764a3d9335a1a.html

String.valueOf()是用来将其他类型的数据转换为string型数据的
例如:System.out.println(String.valueOf('c'));
打印为:c

 

 

2、Split就是对字符串进行分割。

去除字符串WW中的“-”字符:

方法1:

string ww = "1-2-3-4-5-6-7-8-9";
        String[] zx = ww.Split('-');
        int o1;
        for (o1 = 0; o1 < zx.Length; o1++)
        {
            Response.Write(zx[o1]);
        }

方法2:

string a = "1-2-3-4-5-6-7-8-9";
        string[] arr = a.Split('-');
        string tempa = "";
        foreach (string ch in arr)
        {
            tempa += ch;
        }
        Response.Write(tempa);

 

其他示例:

namespace TestSplit
}

结果:acdefacdefacdfe

 

使用多个字符进行分割 看下面的例子:

namespace TestSplit
}
     

结果:acdfacdfacdf

 

相关文章:

  • 2022-12-23
  • 2021-06-15
  • 2021-11-22
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2022-02-20
猜你喜欢
  • 2022-12-23
  • 2022-01-07
  • 2021-10-31
  • 2022-01-18
  • 2021-09-26
  • 2022-12-23
相关资源
相似解决方案