如何检查字符串vb.net中的caseing [英] how to check caseing in string vb.net

查看:92
本文介绍了如何检查字符串vb.net中的caseing的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查字符串vb.net中的caseing



i想检查wheater标签文本是否为

大写或

小写或

标题案例或

判刑案例或

切换案例



请帮助!!!



i得到了上下的解决方案

ie

< pre lang =vb> char .isUpper()
char .isLower()





标题案例或

判刑案例或

切换案例



仍然知道如何检查

解决方案

我不认为这是一个万能的解决方案为了这。在这种情况下确定字符串是否是一种简单的方法是将其转换为该情况,然后检查并查看转换后的版本是否与原始版本相同。您可以参考这篇文章 - Letter Case Conversion Algorithms:Title Case,Toggle案例 [ ^ ] - 它为标题和切换案例提供了一些代码。你也可以使用旧的VB6 StrConv方法,它仍然可用(ProperCase与TitleCase相同):

  Dim  s 作为 字符串 =  这是一个测试 
MessageBox.Show(StrConv(s,VbStrConv.ProperCase))





请注意,正确/标题的情况可能不是您想要的。使用上述标题/正确的案例定义的双城记将为您带来双城记。我希望Of小写。一个自定义的,逐个字符的解决方案可能不那么复杂,并且可以更好地控制结果。


isUpper和isLower应用于字符串中的单个字符。我认为更好的解决方案是创建一个临时字符串,格式化为您想要的格式并返回比较。



作为示例(对于ProperCase)

 如果 字符串 .Format(yourString,vbStrConv。 ProperCase)= yourString 然后 
' 您的代码适当的情况
结束 如果


how to check caseing in string vb.net

i want to check wheater label text is in
upper case or
lowercase or
title case or
sentence case or
Toggle case

please help!!!

i got soln for lower and upper
i.e

char.isUpper() 
char.isLower()



title case or
sentence case or
Toggle case

still dnt knw how to check

解决方案

I don't think there's a one-size-fits-all solution for this. A simple way of determining whether your string IS in that case is to convert it TO that case and then check and see if the converted version is equal to the original. You can reference this article-- Letter Case Conversion Algorithms: Title Case, Toggle Case[^]--which gives some code for title and toggle cases. You could also use the old VB6 StrConv method, which is still available (ProperCase is the same as TitleCase):

Dim s As String = "this is a test"
MessageBox.Show(StrConv(s, VbStrConv.ProperCase))



Note that proper/title case might not quite be what you might want. "A Tale of Two Cities" using the above title/proper case definitions gets you "A Tale Of Two Cities". I'd want that "Of" to be lowercase. A custom, character by character, solution is likely not that complex and will give you finer control of the results.


isUpper and isLower apply to single characters within a string. I think a better solution is to create a temporary string that is formatted the way you want it and return the comparison.

As an example (for ProperCase)

If String.Format(yourString, vbStrConv.ProperCase) = yourString then
    'your code for proper case
End If 


这篇关于如何检查字符串vb.net中的caseing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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