有一个字符串
比如
string a = "123abc";长度不是定值
string b = "sssss";
要把他转换成 只保留第一位和最后一位,其他全部替换成*****
还有一个问题就是如何获取本页的完整的url
谢谢各位
------解决方案--------------------------------------------------------
- C# code
char[] c;string s = "a12121afdafadfdsd";c = s.ToCharArray();for (int i = 1; i < c.Length-1; i++) { c[i] = '*';}Response.Write(new string(c));
------解决方案--------------------------------------------------------
- C# code
using System;using System.Collections.Generic;using System.Text;namespace Csharp_Test_Code{ class Run { static void Main() { string str = GetString("sas"); } static string GetString(string str) { if (str.Length <= 2) { return str; } StringBuilder sb = new StringBuilder(); sb.Append(str[0]); char c = str[str.Length - 1]; sb.Append('*', str.Length - 2); sb.Append(c); return sb.ToString(); } }}
------解决方案--------------------------------------------------------
- C# code
string c = null; c = "abcde"; c = string.Format("*{0}*", Strings.Mid(c, 2, Strings.Len(c) - 2));
------解决方案--------------------------------------------------------