- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当尝试使用 appendFormat 附加到 NSMutableString 时 - 它会添加空格。
NSM 只是一个 NSMutableString,att_1_variable 和 att_2_variable 是 NSString
[NSM appendFormat:@"<tagname att_1=\" %@ \" att_2=\" %@ \">", att_1_variable, att_2_variable];
结果是:
<tagname myattribute=" ContentOfVariable " title=" ContentOfVariable ">
在传入我正在做的字符串之前:
NSString* att_1_variable = [att_1_variable_orginal stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
有什么办法解决这个问题吗?
谢谢问候基督徒
最佳答案
您要自己添加空格,方法是将它们包含在格式字符串中。在 C 中,引号的转义序列只是 \"
,没有尾随(或前导)空格。所以你想要:
[NSM appendFormat:@"<tagname myattribute=\"%@\" title=\"%@\">",
attributeVariable, titleVariable];
如果引号和之后的变量内容之间有空格,那么您的输入变量将用空格填充。你可以用类似的东西修剪那些:
NSString *trimmedAttributeVariable = [attributeVariable
stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
...
[NSM appendFormat:@"<tagname myattribute=\"%@\" title=\"%@\">",
trimmedAttributeVariable, ...
这将从两端修剪空格和制表符。
关于iphone - NSMutableString appendFormat ... 添加空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9057678/
我正在使用仪器来检测一些泄漏,但有一些泄漏我无法解决; NSMutableString *textedetails = [[NSMutableString alloc] init];
是否可以在不删除 @ 的情况下以某种方式执行此操作?它不喜欢@ cJavaScript.AppendFormat(@" function GetNextProductI
当尝试使用 appendFormat 附加到 NSMutableString 时 - 它会添加空格。 NSM 只是一个 NSMutableString,att_1_variable 和 att_2_v
我的 C# 应用程序中有一个 StringBuilder 实例,其中我希望根据上下文用不同数量的空格填充某些行。我的用法很简单: StringBuilder MyStringBuilder = new
我在这个site 上看到过说明 AppendFormat 用法的 StringBuilder 代码示例: using System; using System.Text; class Program
我正在尝试使用 StringBuilders AppendFormat 方法创建一个包含数据的表。我希望第二列和第三列中的文本左对齐。 这是我在谷歌上找到的一个例子: http://www.cshar
我能做到: myStringBuilder.AppendFormat("hello {0}", "world"); 但是我做不到: myStringBuilder.AppendFormatLine("
我想在字符串生成器 AppendFormat 中有一个简短的 if ,这样当数量不相同时我可以将两种不同的颜色添加到 td。 这就是我的尝试: foreach (var item in dataObj
我正在尝试使用字符串生成器和附加格式来构建一些 html。如何在不出现以下错误的情况下使用逐字字符串文字和附加格式:“索引(从零开始)必须大于或等于零且小于参数列表的大小。” 看这个例子: Strin
我一直在创建动态字符串以 append 到 StringBuilder,如下所示: StringBuilder sb = new StringBuilder(); string bla = "bla"
这个问题在这里已经有了答案: String.Format exception when format string contains "{" (5 个答案) Escape curly brace '
我目前正在做一个几年前写的项目。 我遇到了这一行: stringBuilder.AppendFormat("{0}", value); 据我所知,它正在“格式化”这一事实没有任何区别。没有插入其他字符
鉴于此: NSString *innerXml = @"somevalue"; NSMutableString *xml = [[NSMutableString alloc] init]; 哪个更快?
我正在将 C# 代码转换为 Java,我遇到了这一行(其中 i 是一个 int)。 sb.AppendFormat("\\u{0:X04}", i); 据我所知,Java 在其 StringBuild
我对 StringBuilder 类的 AppendFormat 方法有疑问。我正在创建表格并在字符串生成器对象中附加数据以将其作为邮件发送,但是当我看到我发送的邮件时,它看起来不像表格,它的标题和相
我想使用 appendFormat 将字符串附加到 NSMutableString,插入空格以获得我的字符串的最小长度。 在 objective-c 中,我只是使用 [text.mutableStri
我想知道 StringBuilder,我有一个问题希望社区能够解释。 让我们忘掉代码的可读性,哪些是更快,为什么? StringBuilder.Append: StringBuilder sb = n
我有一个浮点值,我想以格式字符串显示它,如果它对应于 int,则显示整数,如果不对应,则显示一位小数。 像这样: 3.1 3 2.9 2.8 现在我陷入了这个概念,我会做类似的事情: float my
最近的 question came up关于使用 String.Format()。我的部分回答包括使用 StringBuilder.AppendLine(string.Format(...)) 的建议
我是一名优秀的程序员,十分优秀!