C#中的字符串和指针 [英] string and pointers in C#

查看:931
本文介绍了C#中的字符串和指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算字符串中的元音数量,但是我想通过使用C#中的指针来计算它我该怎么办?我面临的问题是我没有办法在C中做到这一点,但没有在C#中得到

i want to calculate number of vowels in a string but i want to calculate it by using pointers in C# how i do that i am facing problem i no how to do that in C but not getting in C#

推荐答案

这样做的一种方法(另一种方法是使用RegEx,但这可能会过分恕我直言)会遍历字符串中的每个字符并计算元音的数量. br/>
/ravi
One way (another would be to use RegEx, but that might be overkill IMHO) to do this would be to iterate through each character in the string and count the number of vowels.

/ravi


您是认真的吗?对于初学者,忘记指针了;不需要它们.

当您 pin 锁定对象时,只能访问不安全代码的指针,这在非常特殊的情况下会使用.如果您不能想到使用.NET字符串这样简单的事情,那么本主题对您而言太高级了.只需查看 http://msdn.microsoft.com/en-us/library/system.string. aspx [^ ].

—SA
Are you serious? For starters, forget the pointers; they are not needed.

Pointers are accessible only for unsafe code when you pin an object, which is used in a very special cases. If you cannot figure such a simple thing as working with .NET strings, this topic is way too advanced for you. Just see http://msdn.microsoft.com/en-us/library/system.string.aspx[^].

—SA


这篇关于C#中的字符串和指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆