本文介绍了从NSString获取长值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从NSString获取一个long值.

例如,我有这个:

NSString *test = @"5437128";

我需要:

long myLong = 5437128;

如何从NSString获取此long值?

谢谢您,它将对我有帮助!

Thank you, it will help me!

推荐答案

像下面的代码一样使用NSScanner:

Use the NSScanner like in the following code:

  unsigned x;

[[NSScanner scannerWithString: s2] scanHexInt: &x];

当键入scanHexInt时,在扫描时停止并查看自己需要的那个-有很多从字符串中获取值的可能性....

when typing the scanHexInt stop at scan and see yourself which one you need - there are many possibilities to get values from strings....

您可能要使用scanlonglong ...将变量声明为long

You might want to use scanlonglong... having declared your variable as long

这篇关于从NSString获取长值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 22:24