我如何 float.TryParse 整行的子字符串?

How can I float.TryParse on a substring of a whole line?

我正在制作一个文本序列化系统,其中每一行都包含 memberName value。我可以通过查找 space 的字符索引并使用 string.Compare(line, 0, memberName, 0, indexOfSpace) 来识别成员而无需分配子字符串,但是当我去解析该行的其余部分以获取值时,我似乎需要创建一个子字符串以传递给 float.TryParse(以及其他原始类型的类似方法)。

其他 class 中是否有类似 TryParse 的方法采用子字符串索引?否则,有没有什么地方可以看到这些方法的源代码来实现我自己的变体?

Are there methods like TryParse in some other class which take substring indices?

没有

Otherwise, is there somewhere I can see the source code of those methods to implement my own variations?

是的,Double.TryParse 在 Microsoft 参考源存储库中可用:


作为一般建议:在大多数情况下,创建子字符串非常不太可能与性能或内存使用情况。在投入大量精力对此处进行微优化之前,请确保确实您的应用程序的瓶颈。