将文本字段中的字符串附加到文件名
我正在尝试将用户输入的字符串附加到文件名。
[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"userfile\"; filename= \".jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
我有一个文本字段,我希望将该字段中的输入附加到 .jpg 之前。我一直在玩我能找到的字符串东西,但不知道如何将它们放在上面。
I'm trying to append a string input from the user to a filename.
[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"userfile\"; filename= \".jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
I have a text field I would like the input from the field to be appended before the .jpg. I've been playing with the string stuff I can find, but don't know how to put them in up above.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我必须做出一些假设,因为你的问题不够清晰,但是......
假设 body 是一个 NSMutableData 对象。
假设您的
UITextField
名为“textFieldName”。例如,假设 textFieldName 包含文本“TextInTextField”。
如果您希望生成一个字符串“
Content-Disposition: form-data;”名称=“用户文件”; filename= "TextInTextField.jpg"
',然后执行以下操作:stringWithFormat:
& NSString 的 initWithFormat: 方法采用多个参数。第一个是格式或模板,用于将数据(来自以下参数)(在本例中为字符串)插入到所述格式中。您可以使用%@
或%i
等指示插入数据的位置。在这种情况下,您将使用%@
插入字符串。当然,这可以嵌套到原始的appendData:调用中,如下所示:
I have to make some assumptions because your question lacks for clarity, but...
Assuming that body is an
NSMutableData
object.Assuming that your
UITextField
is named 'textFieldName'.Assuming, for example, that textFieldName contains the text 'TextInTextField'.
If you are looking to produce a string that reads '
Content-Disposition: form-data; name="userfile"; filename= "TextInTextField.jpg"
', then do this:The
stringWithFormat:
&initWithFormat:
methods of NSString take multiple arguments. The first is a format, or template, that is used by inserting data (from the following arguments), in this case a string, into said format. You indicate where to insert the data with a%@
or%i
and so on. In this case you would use%@
to insert a string.Of course this can be nested into the original appendData: call like so: