如何使用从Objective-c中的URL查询接收的逗号分隔值?

时间:2021-01-21 00:23:28

How do I use comma-separated-values received from a URL query in Objective-c? when I query the URL I get csv such as ("OMRUAH=X",20.741,"3/16/2010","1:52pm",20.7226,20.7594). How do I capture and use this for my application?

如何使用从Objective-c中的URL查询接收的逗号分隔值?当我查询URL时,我得到csv,如(“OMRUAH = X”,20.741,“3/16/2010”,“1:52 pm”,20.7226,20.7594)。如何捕获并将其用于我的应用程序?

2 个解决方案

#1


0  

You have two options:

你有两个选择:

Use a CSV parser: http://freshmeat.net/projects/ccsvparse

使用CSV解析器:http://freshmeat.net/projects/ccsvparse

Or parse the data yourself into an array:

或者将数据自己解析为数组:

// myString is an NSString object containing your data
NSArray *array = [myString componentsSeparatedByString: @","];

#2


0  

I recently dealt with CSV parsing for Yahoo! Finance as well. I used Ragel to write a parser in C that was good enough for the CSV I was getting. It handled everything but escaped quotes, which are not going to show up much in stock quotes. It was pretty painless and a good learning experience. I'd post the code, but it was work-for-hire, so I don't own it.

我最近处理了Yahoo!的CSV解析财务也是如此。我用Ragel在C中编写了一个解析器,它对于我得到的CSV来说已经足够了。它处理了一切但是没有报价的报价,这些报价不会出现太多的股票报价。这是非常轻松和良好的学习经验。我发布了代码,但它是出租工作,所以我不拥有它。

Turning a C string into an NSString is easy. If you have it as an NSData, as you likely do at the end of a URL download, just do [[NSString alloc] initWithData:csvData encoding:NSUTF8StringEncoding]. If you have a pointer to a character buffer instead, use [[NSString alloc] initWithBytes:buffer length:buflen encoding:NSUTF8StringEncoding]. buflen could be strlen(buffer) if buffer is a normal, NUL-terminated C string.

将C字符串转换为NSString很容易。如果您将它作为NSData,就像您在URL下载结束时那样,只需执行[[NSString alloc] initWithData:csvData encoding:NSUTF8StringEncoding]。如果你有一个指向字符缓冲区的指针,请使用[[NSString alloc] initWithBytes:buffer length:buflen encoding:NSUTF8StringEncoding]。如果缓冲区是正常的,NUL终止的C字符串,则buflen可以是strlen(缓冲区)。

#1


0  

You have two options:

你有两个选择:

Use a CSV parser: http://freshmeat.net/projects/ccsvparse

使用CSV解析器:http://freshmeat.net/projects/ccsvparse

Or parse the data yourself into an array:

或者将数据自己解析为数组:

// myString is an NSString object containing your data
NSArray *array = [myString componentsSeparatedByString: @","];

#2


0  

I recently dealt with CSV parsing for Yahoo! Finance as well. I used Ragel to write a parser in C that was good enough for the CSV I was getting. It handled everything but escaped quotes, which are not going to show up much in stock quotes. It was pretty painless and a good learning experience. I'd post the code, but it was work-for-hire, so I don't own it.

我最近处理了Yahoo!的CSV解析财务也是如此。我用Ragel在C中编写了一个解析器,它对于我得到的CSV来说已经足够了。它处理了一切但是没有报价的报价,这些报价不会出现太多的股票报价。这是非常轻松和良好的学习经验。我发布了代码,但它是出租工作,所以我不拥有它。

Turning a C string into an NSString is easy. If you have it as an NSData, as you likely do at the end of a URL download, just do [[NSString alloc] initWithData:csvData encoding:NSUTF8StringEncoding]. If you have a pointer to a character buffer instead, use [[NSString alloc] initWithBytes:buffer length:buflen encoding:NSUTF8StringEncoding]. buflen could be strlen(buffer) if buffer is a normal, NUL-terminated C string.

将C字符串转换为NSString很容易。如果您将它作为NSData,就像您在URL下载结束时那样,只需执行[[NSString alloc] initWithData:csvData encoding:NSUTF8StringEncoding]。如果你有一个指向字符缓冲区的指针,请使用[[NSString alloc] initWithBytes:buffer length:buflen encoding:NSUTF8StringEncoding]。如果缓冲区是正常的,NUL终止的C字符串,则buflen可以是strlen(缓冲区)。