日期:2014-05-18 浏览次数:20444 次
char[] c; string s = "a12121afdafadfdsd"; c = s.ToCharArray(); for (int i = 1; i < c.Length-1; i++) { c[i] = '*'; } Response.Write(new string(c));
------解决方案--------------------
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(); } } }
------解决方案--------------------
string c = null; c = "abcde"; c = string.Format("*{0}*", Strings.Mid(c, 2, Strings.Len(c) - 2));
------解决方案--------------------