如何添加两个字符串值并将其显示为字符串值 [英] how to add two string value and display it in string value
本文介绍了如何添加两个字符串值并将其显示为字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
tot = int.Parse(tot + amtusd).ToString();
我要加法不要串联.
i want addition not concatenation.
推荐答案
尝试一下,
Try this,
tot = (Convert.ToInt32(amtusd) + Convert.ToInt32(tot)).ToString();
或
or
tot = (int.Parse(amtusd) + int.Parse(tot)).ToString();
尝试一下:
Try this :
string tot = (int.Parse(tot) + int.Parse(amtusd)).ToString();
其中一种方式:
One of the ways:
// Sample addition of string and a number
string concatenatedString = String.Empty;
string someString1 = "StringABC";
string someString2 = "1234";
int someNumber = 678;
concatenatedString = someString1 + someString2 + someNumber.ToString();
现在,像这样串联起来的几个字符串就可以了.如果要串联很多,则应使用 StringBuilder [ ^ ].
更新:
如果要添加数字(以字符串格式),然后再次将其转换为字符串,则:
对于数字字符串,请阅读:Int.Parse
或Convert.ToInt32
要将数字转换为字符串,请阅读:ToString()
方法.
Now, couple of strings if concatenated is fine like this. If you want to concatenate lots of them, then you should use StringBuilder[^].
UPDATE:
If numbers (in string format) to be added and then again converted to string then:
for string to numbers, read: Int.Parse
or Convert.ToInt32
for converting numbers to string, read: ToString()
method.
这篇关于如何添加两个字符串值并将其显示为字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文