- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 Convert 类中进行以下重载对我来说是有意义的
public static double ToDouble(string value, IFormatProvider provider);
示例:
Console.WriteLine(Convert.ToDouble("3223.2", CultureInfo.InvariantCulture)); // success
Console.WriteLine(Convert.ToDouble("3223,2", new CultureInfo("fr-FR"))); // success
Console.WriteLine(Convert.ToDouble("3223.2", new CultureInfo("fr-FR"))); // failure
但是使用以下重载的示例是什么?
public static int ToInt32(string value, IFormatProvider provider);
下面一切都失败了:
Console.WriteLine(Convert.ToInt32("3223.2", CultureInfo.InvariantCulture));
Console.WriteLine(Convert.ToInt32("3223,2", new CultureInfo("fr-FR")));
Console.WriteLine(Convert.ToInt32("3223.2", new CultureInfo("fr-FR")));
换句话说,是否有任何有效的整数字符串表示形式(在任何区域性中),如果不指定 IFormatProvider 就无法将其转换为 int?
最佳答案
当您使用 Convert.ToInt32 的简单版本时,您仍在使用采用只读 CultureInfo.CurrentCulture 的重载,如查看 reference source of Convert.ToInt32 所示。
public static int ToInt32(String value) {
if (value == null)
return 0;
return Int32.Parse(value, CultureInfo.CurrentCulture);
}
关键是,许多文化,无论是否定制,都可以使用不同的字符来进行转换等常见操作,并且需要适当的支持结构。
这里是自定义 CultureInfo 的奇怪使用示例,它允许将字符串奇怪地转换为整数
CultureInfo ci = new CultureInfo("it-IT");
ci.NumberFormat.NegativeSign = "@";
int number = Convert.ToInt32("@10", ci);
Console.WriteLine(number);
关于.net - 为什么 Convert.ToInt32 接受 IFormatProvider?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41241619/
我正在阅读 Beginning Scala 并尝试使用 REPL 中的示例。 我创建了一个 xml 和一个 toInt 函数,如下所示 val x = {(1 to 3).map(i => {i})}
第一次发帖,请多多关照。我对编码相当陌生,正在努力了解 SWIFT 及其可选项目。非常感谢专业人士的一些建议! 我正在编写一个简单的应用程序,用户在其中输入文本字段,然后在应用程序中进行一些乘法运算,
toInt StringLike 中的方法不带任何参数,只能解析十进制。因此,要解析二进制、十六进制等,我们需要求助于 Java 的 Integer#parseInt(String s, int ra
我正在读我的一本教科书,在解释它引入的代码方面做得很差。这里是示例代码: int choice; QString response; do { cout QUIT) 最佳答案 根据QT Docum
以下错误:无法使用类型为“(@lvalue Int?, @lvalue UInt32)”的参数列表调用“==” @IBOutlet weak var textBox: UITextField! @IB
以下代码中的 println 有效(有或没有 toInt ) println("retweets : ", e.getOrElse("retweets", 0).toInt) top10Tweets(
从另一个页面启动幻灯片拼图项目时出错。 class PuzzlePage extends StatefulWidget { final int rows, columns; Puzzl
我正在尝试使用 String.toInt 将字符串转换为整数。但是,当我想将结果绑定(bind)到变量,然后用它做一些简单的数学运算时,我收到此错误: Function add is expectin
我正在尝试创建一个简单的用户输入,但我在 swift 中找到的唯一函数就是这个 func input() -> String { var keyboard = NSFileHandle.fil
这个问题在这里已经有了答案: .toInt() removed in Swift 2? (5 个答案) 关闭 7 年前。 我刚刚升级到 Swift 2.0,我不确定为什么这行代码不起作用。我知道 t
QString 有 toInt()、toLong() 等几个方法 这些方法接收一个指向 bool 的指针,确定转换是否成功,如下所示: int QString::toInt(bool * ok = 0
我有一个 32 位十六进制值,我希望将其转换为整数。 给定十六进制字符串 C71C5E00,以下方法都提供以下错误: java.lang.NumberFormatException: For inpu
这是关于 RedisClient ,这是一个 C++ 客户端。 我知道您不能在 Redis 中存储整数(在内部转换)。 RedisSyncClient::command 本身不支持整数,因为 Redi
我有一个包含“-3.5”的“QString”,但是如果我尝试使用“toInt”方法将其转换为整数,它会返回 0。为什么? QString strTest = "-3.5"; int i
为什么这段代码会抛出异常? val x = new { def toInt(n: Int) = n*2 } x.toInt(2) scala.tools.nsc.symtab.Types$TypeEr
如果是 long.isValidInt,那么很明显,它求值为相应的 Int 值。 但如果不是呢?是否等同于简单地删除前导位? 最佳答案 Is it equivalent to simply dropp
所以我正在学习 Scala,并且遇到了这个棘手的问题...... 如果我们有一个 String 并想将其转换为 Int,我在网上找到的所有示例都说:“这很简单!只需使用 >String.toInt!”
我正在开发一个使用文本字段并将其转换为整数的应用程序。以前我的代码 textField.text.toInt() 成功了。现在 Swift 将此声明为错误并告诉我这样做 textField.text!
这个问题在这里已经有了答案: .toInt() removed in Swift 2? (5 个答案) 关闭 7 年前。
您好,我正在尝试重载类的赋值运算符以返回类成员(数据)。 class A{ public: int32_t ToInt32() { return this->data; } void Set
我是一名优秀的程序员,十分优秀!