473,765 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert Words in Strings to Caps

I know this is probably a very overworked issue but thought I'd share the
code below to convert words in a text string to capitalize the first letter
of the word using an array of word delimiters. Hope it not too simplistic
for posting on thie newsgroup:

Private Overloads Function CapWords(ByVal textstring As String, ByRef
Delimiters() As Char) As String
If textstring Is Nothing OrElse textstring.Leng th <= 0 Then Return
Nothing
If textstring.leng th=1 then return textstring.ToUp per
Dim i As Integer = 1
Dim c() As Char = textstring.ToCh arArray
c(0) = Char.ToUpper(c( 0))
While i < c.Length - 1
If Array.IndexOf(D elimiters, c(i)) >= 0 Then c(i + 1) =
Char.ToUpper(c( i + 1))
i += 1
End While
Dim b As New StringBuilder
Return b.Append(c).ToS tring
End Function

Private Overloads Function CapWords(ByVal textstring As String, ByRefl
Delimiter As Char) As String
Dim Delimiters() As Char = {Delimiter}
Return CapWords(textst ring, Caps, Delimiters)
End Function

--
Dennis in Houston
Feb 22 '06 #1
5 3127
On Tue, 21 Feb 2006 17:44:02 -0800, Dennis
<De****@discuss ions.microsoft. com> wrote:
I know this is probably a very overworked issue but thought I'd share the
code below to convert words in a text string to capitalize the first letter
of the word using an array of word delimiters. Hope it not too simplistic
for posting on thie newsgroup:

Private Overloads Function CapWords(ByVal textstring As String, ByRef
Delimiters() As Char) As String
If textstring Is Nothing OrElse textstring.Leng th <= 0 Then Return
Nothing
If textstring.leng th=1 then return textstring.ToUp per
Dim i As Integer = 1
Dim c() As Char = textstring.ToCh arArray
c(0) = Char.ToUpper(c( 0))
While i < c.Length - 1
If Array.IndexOf(D elimiters, c(i)) >= 0 Then c(i + 1) =
Char.ToUpper(c (i + 1))
i += 1
End While
Dim b As New StringBuilder
Return b.Append(c).ToS tring
End Function

Private Overloads Function CapWords(ByVal textstring As String, ByRefl
Delimiter As Char) As String
Dim Delimiters() As Char = {Delimiter}
Return CapWords(textst ring, Caps, Delimiters)
End Function


I'm rewritting a VB6 app that has a routine to capitalize first letter
of strings of title and artist extracted from mp3 file tags. The tags
are often mixed case or can be all lower case. I have not rewritten
this routine yet, but your post on the subject caught my eye. My VB6
routine used a different approach. I curious how you handle some of
the special cases below.

How do you handle:
Roman Numerals - vii s/b VII, or ignored, but not Vii
Acronyms - cd s/b CD, and not Cd, but jr. s/b Jr.
Certain Names - o'conner s/b O'Conner, but not O'conner
word1/word2 - s/b Word1/Word2, but not Word1/word2

Thanks,

Gene
Feb 22 '06 #2
As an alternative, you can use the TextInfo.ToTitl eCase method as follows:

Dim myTI As System.Globaliz ation.TextInfo = New System.Globaliz ation.CultureIn fo("en-US",
False).TextInfo
Return myTI.ToTitleCas e(MyString)

Jim Wooley
I know this is probably a very overworked issue but thought I'd share
the code below to convert words in a text string to capitalize the
first letter of the word using an array of word delimiters. Hope it
not too simplistic for posting on thie newsgroup:

Private Overloads Function CapWords(ByVal textstring As String, ByRef
Delimiters() As Char) As String
If textstring Is Nothing OrElse textstring.Leng th <= 0 Then
Return
Nothing
If textstring.leng th=1 then return textstring.ToUp per
Dim i As Integer = 1
Dim c() As Char = textstring.ToCh arArray
c(0) = Char.ToUpper(c( 0))
While i < c.Length - 1
If Array.IndexOf(D elimiters, c(i)) >= 0 Then c(i + 1) =
Char.ToUpper(c( i + 1))
i += 1
End While
Dim b As New StringBuilder
Return b.Append(c).ToS tring
End Function
Private Overloads Function CapWords(ByVal textstring As String,
ByRefl
Delimiter As Char) As String
Dim Delimiters() As Char = {Delimiter}
Return CapWords(textst ring, Caps, Delimiters)
End Function

Feb 22 '06 #3
Thanks but don't think this works for other than space delimiters...I needed
a routine that would capitalize things like myname-hining, dennis.
--
Dennis in Houston
"Jim Wooley" wrote:
As an alternative, you can use the TextInfo.ToTitl eCase method as follows:

Dim myTI As System.Globaliz ation.TextInfo = New System.Globaliz ation.CultureIn fo("en-US",
False).TextInfo
Return myTI.ToTitleCas e(MyString)

Jim Wooley
I know this is probably a very overworked issue but thought I'd share
the code below to convert words in a text string to capitalize the
first letter of the word using an array of word delimiters. Hope it
not too simplistic for posting on thie newsgroup:

Private Overloads Function CapWords(ByVal textstring As String, ByRef
Delimiters() As Char) As String
If textstring Is Nothing OrElse textstring.Leng th <= 0 Then
Return
Nothing
If textstring.leng th=1 then return textstring.ToUp per
Dim i As Integer = 1
Dim c() As Char = textstring.ToCh arArray
c(0) = Char.ToUpper(c( 0))
While i < c.Length - 1
If Array.IndexOf(D elimiters, c(i)) >= 0 Then c(i + 1) =
Char.ToUpper(c( i + 1))
i += 1
End While
Dim b As New StringBuilder
Return b.Append(c).ToS tring
End Function
Private Overloads Function CapWords(ByVal textstring As String,
ByRefl
Delimiter As Char) As String
Dim Delimiters() As Char = {Delimiter}
Return CapWords(textst ring, Caps, Delimiters)
End Function


Feb 23 '06 #4
How do you handle:
Roman Numerals - vii s/b VII, or ignored, but not Vii
Acronyms - cd s/b CD, and not Cd, but jr. s/b Jr.
Certain Names - o'conner s/b O'Conner, but not O'conner
word1/word2 - s/b Word1/Word2, but not Word1/word2
The first letter after a delimiter gets capitalized and that's all it does.
You can pass an array of delimiters ( ,;,-, etc). If you want special cases,
then add them to the routine using the .replace method for some but names
like o'conner will get capitalized to O'Conner if you pass a ' as one of the
delimiters but also don't would end up Don'T. The possibilities are endless
like McDonald, etc.

I also am using this for my Music LIbrarian program and it get's most of the
cases. I handle others manually that don't fit. I think you will find that
will be the best way since the possible exceptions are endless except for a
few common ones. --
Dennis in Houston
"gene kelley" wrote:
On Tue, 21 Feb 2006 17:44:02 -0800, Dennis
<De****@discuss ions.microsoft. com> wrote:
I know this is probably a very overworked issue but thought I'd share the
code below to convert words in a text string to capitalize the first letter
of the word using an array of word delimiters. Hope it not too simplistic
for posting on thie newsgroup:

Private Overloads Function CapWords(ByVal textstring As String, ByRef
Delimiters() As Char) As String
If textstring Is Nothing OrElse textstring.Leng th <= 0 Then Return
Nothing
If textstring.leng th=1 then return textstring.ToUp per
Dim i As Integer = 1
Dim c() As Char = textstring.ToCh arArray
c(0) = Char.ToUpper(c( 0))
While i < c.Length - 1
If Array.IndexOf(D elimiters, c(i)) >= 0 Then c(i + 1) =
Char.ToUpper(c (i + 1))
i += 1
End While
Dim b As New StringBuilder
Return b.Append(c).ToS tring
End Function

Private Overloads Function CapWords(ByVal textstring As String, ByRefl
Delimiter As Char) As String
Dim Delimiters() As Char = {Delimiter}
Return CapWords(textst ring, Caps, Delimiters)
End Function


I'm rewritting a VB6 app that has a routine to capitalize first letter
of strings of title and artist extracted from mp3 file tags. The tags
are often mixed case or can be all lower case. I have not rewritten
this routine yet, but your post on the subject caught my eye. My VB6
routine used a different approach. I curious how you handle some of
the special cases below.

How do you handle:
Roman Numerals - vii s/b VII, or ignored, but not Vii
Acronyms - cd s/b CD, and not Cd, but jr. s/b Jr.
Certain Names - o'conner s/b O'Conner, but not O'conner
word1/word2 - s/b Word1/Word2, but not Word1/word2

Thanks,

Gene

Feb 23 '06 #5
It does work for hyphen delimeted. I altered the sample on http://msdn.microsoft.com/library/de...eCaseTopic.asp
and got the following results:

testing-hYPhen to lowercase: testing-hyphen
testing-hYPhen to uppercase: TESTING-HYPHEN
testing-hYPhen to titlecase: Testing-Hyphen

It doesn't work with Mc/Mac/O' however.

Jim Wooley
Thanks but don't think this works for other than space delimiters...I
needed a routine that would capitalize things like myname-hining,
dennis.

"Jim Wooley" wrote:
As an alternative, you can use the TextInfo.ToTitl eCase method as
follows:

Dim myTI As System.Globaliz ation.TextInfo = New
System.Globaliz ation.CultureIn fo("en-US",
False).TextInfo
Return myTI.ToTitleCas e(MyString)
Jim Wooley

Feb 23 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2966
by: Klaus Neuner | last post by:
Hello, I need a function that converts a list into a set of regexes. Like so: string_list = print string_list2regexes(string_list) This should return something like:
7
5465
by: Timo Haberkern | last post by:
Hi there, i have some troubles with my TSearch2 Installation. I have done this installation as described in http://www.sai.msu.su/~megera/oddmuse/index.cgi/Tsearch_V2_compound_words <http://www.sai.msu.su/%7Emegera/oddmuse/index.cgi/Tsearch_V2_compound_words> I used the german myspell dictionary from http://lingucomponent.openoffice.org/spell_dic.html and converted it with my2ispell
9
5273
by: Steven | last post by:
Hello, I have a question about strcmp(). I have four words, who need to be compared if it were two strings. I tried adding the comparison values like '(strcmp(w1, w2) + strcmp(w3, w4))', where w1 and w2 make up the first string and, w3 and w4 make up the second string. I do not want to allocate memory, then put the words together to create a string only to facilitate strcmp() comparison. My question; Does anyone know how to get the...
4
10460
by: Davor | last post by:
Hi, my name is david. I need to read information from .pdf files and convert to .txt files, and I have to do this on python, I have been looking for libraries on python and the pdftools seems to be the solution, but I do not know how to use them well, this is the example that I found on the internet is: from pdftools.pdffile import PDFDocument from pdftools.pdftext import Text
20
5149
by: dmurray14 | last post by:
Hey guys, I'm a C++ newbie here - I've messed with VB, but I mostly stick to web languages, so I find C++ to be very confusing at times. Basically, I am trying to import a text file, but I want to do it word by word. I am confused as to how to do this. Typically, I would think it would make sense to try and input the words into strings, but for this application I need to use character arrays and pointers. So what's the best way to go...
10
2194
by: Robert R. | last post by:
Hello, i would like to write a piece of code to help me to align some sequence of words and suggest me the ordered common subwords of them s0 = "this is an example of a thing i would like to have".split() s1 = "another example of something else i would like to have".split() s2 = 'and this is another " example " but of something ; now i would still like to have'.split() ....
2
9567
by: Gary | last post by:
Hello, I am trying to force the formatting of a Post Code field on my form, and require that all post codes are processed as FULL CAPS. I do not want to force the user to type on all caps, so would like it if onBlur, or onSubmit, that for example "im1 2ez" becomes "IM1 2EZ". Any help appreciated!! Gary.
10
4969
by: cmdolcet69 | last post by:
Public ArrList As New ArrayList Public bitvalue As Byte() Public Sub addvalues() Dim index As Integer ArrList.Add(100) ArrList.Add(200) ArrList.Add(300) ArrList.Add(400) ArrList.Add(500)
6
5283
by: Bob Altman | last post by:
Hi all, I'm looking for the fastest way to convert an array of bytes to String. I also need to convert a String back to its original Byte() representation. Convert.ToBase64String and Convert.FromBase64String seem like the closest thing I can find to what I'm looking for baked into the base class library. Can anyone suggest a better way to do this? TIA - Bob
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7375
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5419
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.