Groups | Blog | Home
all groups > vb.net > september 2004 >

vb.net : How to find out if character is in caps or not?


Fabricio
9/11/2004 6:39:10 PM
Here she goes Martin...

Public Function SplitWords(ByVal s as string) as string
Dim strAns as string
Dim c as char

For Each c in s
If Char.IsUpper(c) Then
strAns += " "
End If

strAns += c
Next

Return strAns
End Function

-Fabricio
fguzman_slotown@yahoo.com

[quoted text, click to view]
jarosciak NO[at]SPAM gmail-dot-com.no-spam.invalid
9/11/2004 7:36:04 PM
What I really need is a short simple solution for this scenario:

Imagine word like this:
"TheSimpleSolution"
I need to turn it to:
"The Simple Solution"

I need a solution, something which would turn connected words and
separate them using spaces. Basically, a script which would add the
space ahead of each capitalized character.

Please, be so good and let me know, I know I am pretty much asking for
ready script, but whatever you mention, whatever help or sugestion
will be much appreciated.

Thanks a lot.
Martin
jarosciak NO[at]SPAM gmail-dot-com.no-spam.invalid
9/12/2004 12:01:57 AM
Fabricio ,
I don't know how to thank you... you saved me a lot of time and I
really appreciate it.
Thanks a lot.
Martin

backup of this question:
http://www.groupsrv.com/dotnet/viewtopic.php?t=69327
Cor Ligthert
9/12/2004 8:26:43 AM
Fabricio,

Seeing your code I am sure you know the Stringbuilder and just are thinking
something as "why use that for such a simple string".

I have seen that even for short strings the stringbuilder gives beter result
and sometimes OPs are giving a simple sample to use it for long strings.

For Martin, with the stringbuilder the code from Fabricio can be.

Public Function SplitWords(ByVal s as string) as string
Dim strAns as new system.text.stringbuilder
Dim c as char
For Each c in s
If Char.IsUpper(c) Then
strAns.append( " ")
End If
strAns.append(c)
Next
Return strAns.tostring
End Function
[quoted text, click to view]

Cor

Fabricio
9/12/2004 8:39:01 AM
I don't use the Stringbuilder object much... actually I've never used it.
When you say it "gives better results" do you mean performance. Is it more
efficient than a built-in string object. Also, how's its overhead compared
to the string object? Thanks for the info Cor.

-Fabricio
fguzman_slotown@yahoo.com

P.S. What's OP?

[quoted text, click to view]
Fabricio
9/12/2004 8:39:02 AM
No problem bud :-)

-Fabricio
fguzman_slotown@yahoo.com

[quoted text, click to view]
hirf-spam-me-here NO[at]SPAM gmx.at
9/12/2004 12:55:22 PM
* jarosciak@gmail-dot-com.no-spam.invalid (Martin Ho) scripsit:
[quoted text, click to view]

\\\
Imports System.Text
..
..
..
MsgBox(ExpandCaps("ThisIsVeryGood"))
..
..
..
Public Function ExpandCaps(ByVal Text As String) As String
Dim Buffer As New StringBuilder(CInt(Text.Length * 1.3))
For Each c As Char In Text
If Char.IsUpper(c) Then
Buffer.Append(" "c)
End If
Buffer.Append(c)
Next c
Return Buffer.ToString()
End Function
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
hirf-spam-me-here NO[at]SPAM gmx.at
9/12/2004 5:49:39 PM
* "=?Utf-8?B?RmFicmljaW8=?=" <Fabricio@discussions.microsoft.com> scripsit:
[quoted text, click to view]

Strings in .NET are immutable, contantenating two strings will create a
new string object that consists of the concatenated strings. 'StringBuilder'
overcomes this issue.

I suggest to take a look at the documentation for the 'System.String'
and 'System.Text.StringBuilder' classes.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
Cor Ligthert
9/12/2004 6:43:34 PM
Fabricio,

I can can add a lot to the message from Herfried,

What he not explained was OP which means Original Poster

However when you have still question, feel free to ask.

Cor

[quoted text, click to view]

AddThis Social Bookmark Button