System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list
2015-03-04 17:18
1156 查看
static void Main(string[] args) { StringBuilder sb = new StringBuilder(); string test = "124454664{0}89jnhb"; string formattedMessage = string.Format(test, args); }
主要原因是字符串中有{}, 被string.Format调用时报错。
Replace即可。
StringBuilder sb = new StringBuilder(); string test = "124454664{0}89jnhb"; test = test.Replace("{", "[").Replace("}", "]"); string formattedMessage = string.Format(test, args);
或者 将 { 替换为 {{
相关文章推荐
- Row index must be greater than or equal to zero and less than the number of rows.
- Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: startIndex
- Ogre出现”…The minimum corner of the box must be less than or equal to maximum corner”错误
- .NET中使用GridView控件输入数据时出现“ Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"的问题
- jgoodies FormLayout 布局错误The row index 12 must be less than or equal to 10.
- The Behavior version of the Forest is 0 it must be 2 or greater to perform a domain rename: 该服务器不愿意处理该请求。 :8245
- java.lang.IllegalArgumentException: AppIndex: The URI scheme must be 'android-app' and follow the fo
- Semantic Issue: Implicit declaration of function 'SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO' is invali
- why happen "WaitHandles must be less than or equal to 64"
- Err:The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array
- the item width must be less than the width of the UICollectionView minus the section insets left and
- C#查询数据库时问题: Min(1) must be less than or equal to max(-1) in Range object
- The 'to' row (0) must not be less than the 'from' row (1)
- IllegalArgumentException: Argument for @NotNull parameter 'file' of com/intellij/openapi/vfs/VfsUtilCore.virtualToIoFile must not be null
- A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, and a p
- 在myeclipse利用ant构建时遇到The path xxx appears to be part of Subversion 1.7 (SVNKit 1.4) or greater解决办法
- In order to run a trace against SQL Server you must be a member of sysadmin fixed server role or have the ALTER TRACE permission.
- “System.IO.FileLoadException: Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 错误
- SharePoint 报错: The specified file or folder name is too long. The URL path for all files and folders must be 260 characters or less
- Unable to determine the principal end of an association between the types '***. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.