Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 在C中生成固定长度的字符串#_String_C# 4.0 - Fatal编程技术网

String 在C中生成固定长度的字符串#

String 在C中生成固定长度的字符串#,string,c#-4.0,String,C# 4.0,如何根据c#中给出的输入生成固定长度的字符串 你采取了什么方法来解决这个问题?你写了什么代码,为什么不起作用? For example : string s="1"; string newstring ; I want the newstring to be "AB_000001"; // Similarly if s="xyz"; //I want the newstring as newstring = "AB_000xyz"; string basestr = "AB_000000"

如何根据c#中给出的输入生成固定长度的字符串


你采取了什么方法来解决这个问题?你写了什么代码,为什么不起作用?
For example :
string s="1";
string newstring ;
I want the newstring to be "AB_000001";
// Similarly if 
s="xyz";
//I want the newstring as 
newstring = "AB_000xyz";
string basestr = "AB_000000";
string inp = "xyz";
string res = basestr.Substring(0, basestr.Length - inp.Length) + inp;
String s = "AB_000000";
String newString="xyz";
s = s.Remove(s.Length - newString.Length, newString.Length);
s = s + newString;