VB.NET中的ProperCase [英] ProperCase in VB.NET

查看:280
本文介绍了VB.NET中的ProperCase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我希望用户输入一个句子,程序应自动将其更正为ProperCase或Sentence Case。为了实现这一点,我在特定文本框的TextChanged事件中使用了vbStrConv.ProperCase。但问题是它不允许在任何地方输入高位字符,除了单词的开头。



它不应该改变手动输入的UPPER字符的情况,我的意思是我可以让用户输入大写字符吗?



也接受C#代码。



谢谢。

Hello,

I want that as user type a sentence, Program should automatically correct it to ProperCase or Sentence Case. To achive this, I used vbStrConv.ProperCase in TextChanged Event of particular Text box. But problem is It doesn't allow to input upper Characters anywhere except starting of the word.

It should not change the case of Manually typed UPPER Characters, I mean how can I make user able to enter UPPER CASE Characters also ?

C# code is also accepted.

Thank you.

推荐答案

这段代码怎么样?

How about this piece of code?
string proper = "TEST STRING";
CultureInfo properCase = System.Threading.Thread.CurrentThread.CurrentCulture;
TextInfo currentInfo = properCase.TextInfo;
proper = currentInfo.ToTitleCase(currentInfo.ToLower(proper));



输出:


Output:

// proper = "Test String"





还探索:

http://msdn.microsoft.com/en-us/library/system.globalization.textinfo.totitlecase.aspx [ ^ ]

http://www.bondigeek.com/blog/2011/01/17/titleproper- case-in-c / [ ^ ]

HTTP:/ /www.daniweb.com/software-development/csharp/code/306751/format-a-string-to-proper-case-with-c [ ^ ]



Also explore:
http://msdn.microsoft.com/en-us/library/system.globalization.textinfo.totitlecase.aspx[^]
http://www.bondigeek.com/blog/2011/01/17/titleproper-case-in-c/[^]
http://www.daniweb.com/software-development/csharp/code/306751/format-a-string-to-proper-case-with-c[^]


我注意到你希望UPPERcase中的任何字母都保持大写字母。除非你用char检查字符串char,否则我无法想到这样做。例如
I've noticed that you want any letters already in UPPERcase to stay in Upper case. I can't think of anyway to do that unless you examine the string char by char. E.g.
Dim sInput As String = "tesT strinG"
'Get a copy of the input in proper case
Dim sProperCase = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(sInput)
Dim sOutput As String = ""
'Now check for the original having upper case 
For i As Integer = 0 To sInput.Length - 1
    If Char.IsUpper(sInput.Substring(i, 1)) Then
        sOutput += sInput.Substring(i, 1) 'use the original string if the original was upper case
    Else
        sOutput += sProperCase.Substring(i, 1) 'use the copy that was converted to proper case
    End If
Next



输出......


Output ...

TesT StrinG


这篇关于VB.NET中的ProperCase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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