小编the*_*kup的帖子

将C++的sprintf格式字符串翻译成C#的string.Format

我找到了以下C++代码(评论自己添加):

// frame_name is a char array
// prefix is std::string
// k is a for loop counter
// frames is a std::vector string
sprintf(frameName, "%s_%0*s.bmp", prefix.c_str(), k, frames[k].c_str());
Run Code Online (Sandbox Code Playgroud)

然后我尝试将其翻译为C#

// prefix is string
// k is a for loop counter
// frames is List<string>
string frameName = string.Format("{0}_(what goes in here?).bmp", prefix, k, frames[k]);
Run Code Online (Sandbox Code Playgroud)

基本上,C++格式字符串"%s_%0*s.bmp"的C#等价物是什么?

编辑,@ Mark Byers:

我已经尝试了你的代码并做了一个小测试程序:

static void Main(string[] args)
{
    List<string> frames = new List<string>();
    frames.Add("blah");
    frames.Add("cool");
    frames.Add("fsdt");

    string prefix = "prefix";
    int n = …
Run Code Online (Sandbox Code Playgroud)

c# c++ string.format printf

5
推荐指数
1
解决办法
9763
查看次数

标签 统计

c# ×1

c++ ×1

printf ×1

string.format ×1