How to convert an Integer to a String in V8?

血红的双手。 提交于 2019-12-14 03:22:57

问题


I have the following V8 code:

Local<String> getSumString(int32_t a,  int32_t b){
    int32_t sum = a + b;
    return String::Concat(String::New("The sum is: ") , String::New(sum));
}

In the above function I want to add a and b, then want to return a string "The sum is: CALCULATED_SUM " .

I'm having problems in converting the calculated sum to a String so that it can be concatenated with other String.


回答1:


You don't say the nature of the error, but I'm guessing that the end of your output string is mangled, because you're instantiating a String from an int. V8 is interpreting that data as const char * data. You should instantiate an Integer from your int. Your last line will look like this instead:

return String::Concat(String::New("The sum is: ") , Integer::New(sum));


来源:https://stackoverflow.com/questions/22379918/how-to-convert-an-integer-to-a-string-in-v8

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!