Normalizing case in a string - eg. WHAT THIS IS. WHAT -> What this is. What 
Author Message
 Normalizing case in a string - eg. WHAT THIS IS. WHAT -> What this is. What

Does anyone know if there's a way to normalise the case of a string?  eg.

WHAT THIS IS. WHAT THIS IS. -> What this is.  What this is.

I recall that FoxPro has a funtion that does this - called NORMALIZE
(surprise surprise ;-) )

Any help would be greatly appreciated.

Steve



Tue, 26 Oct 2004 14:42:16 GMT  
 Normalizing case in a string - eg. WHAT THIS IS. WHAT -> What this is. What
LowerCaps("WHAT THIS IS. WHAT THIS IS") -> What this is.  What this is.


Quote:
> Does anyone know if there's a way to normalise the case of a string?  eg.

> WHAT THIS IS. WHAT THIS IS. -> What this is.  What this is.

> I recall that FoxPro has a funtion that does this - called NORMALIZE
> (surprise surprise ;-) )

> Any help would be greatly appreciated.

> Steve



Tue, 26 Oct 2004 15:15:58 GMT  
 Normalizing case in a string - eg. WHAT THIS IS. WHAT -> What this is. What
Ooop's  The LowerCaps function was a function that i had in a module already
in my project.  It is not a built in VB function.  Sorry


Tue, 26 Oct 2004 15:29:08 GMT  
 Normalizing case in a string - eg. WHAT THIS IS. WHAT -> What this is. What
This may be what you're after...
'===========
Private Sub Form_Load()
   Dim MyString As String
   MyString = "WHAT THIS IS. WHAT THIS IS"
   MyString = StrConv(MyString, vbProperCase)
   Debug.Print MyString
End Sub
'===========

--
Ken Halter
MS-MVP-VB
http://www.vbsight.com/
Please keep it in the groups..

Quote:

> Does anyone know if there's a way to normalise the case of a string?
> eg.

> WHAT THIS IS. WHAT THIS IS. -> What this is.  What this is.

> I recall that FoxPro has a funtion that does this - called NORMALIZE
> (surprise surprise ;-) )

> Any help would be greatly appreciated.

> Steve



Tue, 26 Oct 2004 15:41:27 GMT  
 Normalizing case in a string - eg. WHAT THIS IS. WHAT -> What this is. What


Quote:
> This may be what you're after...
>    MyString = StrConv(MyString, vbProperCase)

No, it's not. He only wants the first letter of a SENTENCE capitalized.
StrConv() will capitalize the first letter of each WORD.

There is no built-in function to do this.



Tue, 26 Oct 2004 21:15:12 GMT  
 Normalizing case in a string - eg. WHAT THIS IS. WHAT -> What this is. What
That's what I get for staying up 'till 1am on a work night <g>

--
Ken Halter
MS-MVP-VB
http://www.vbsight.com/
Please keep it in the groups..

Quote:



>> This may be what you're after...

>>    MyString = StrConv(MyString, vbProperCase)

> No, it's not. He only wants the first letter of a SENTENCE
> capitalized. StrConv() will capitalize the first letter of each WORD.

> There is no built-in function to do this.



Tue, 26 Oct 2004 23:07:58 GMT  
 Normalizing case in a string - eg. WHAT THIS IS. WHAT -> What this is. What
Jeff is certainly right (there is no built-in function). But if needed,
you can do it without a loop using Instr calls. This is how
I did it (tested code, but not with all possibilities, I'm sure).
Be aware that the beginning of a sentence is recognized:
1. At the very beginning of the string. 2. After a dot + a blank.
However, it should be easy to allow for other sentence
starters, such as ?+blank, !+blank etc. with little extra effort.

Private Function SentenceCase(s As String) As String
  Dim ss As String

  ss = Replace$(s, ". ", Chr$(0))
  ss = Replace$(ss, " ", Chr$(1))
  ss = Replace$(ss, Chr$(0), ". ")
  ss = StrConv(ss, vbProperCase)
  SentenceCase = Replace$(ss, Chr$(1), " ")
End Function

This of course assumes that your original string does not include
Chr$(0) or Chr$(1) which is usually true for text strings.
Although maybe easy to understand, I do not think this code
is anywhere close to optimal performance. I posted it only
because I felt like having a try on this one <g>
Note that you can convert above function to a one-liner
or 'Rickish' function (<g> Sorry, Rick, no insult intended),
similar to

  x = Replace$(StrConv(Replace$(Replace$(Replace$(...

HTH, Nikolaus


Quote:



> > This may be what you're after...

> >    MyString = StrConv(MyString, vbProperCase)

> No, it's not. He only wants the first letter of a SENTENCE capitalized.
> StrConv() will capitalize the first letter of each WORD.

> There is no built-in function to do this.



Wed, 27 Oct 2004 01:21:47 GMT  
 Normalizing case in a string - eg. WHAT THIS IS. WHAT -> What this is. What

Quote:

> Does anyone know if there's a way to normalise the case of a string?  eg.

> WHAT THIS IS. WHAT THIS IS. -> What this is.  What this is.

> I recall that FoxPro has a funtion that does this - called NORMALIZE
> (surprise surprise ;-) )

How do it know?

THREE ZETA RET. "GRAYS" WERE RECOVERED FROM THE U. F. O. CRASH SITE.

--
Joe Foster <mailto:jlfoster%40znet.com>     Got Thetans? <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Wed, 27 Oct 2004 08:48:57 GMT  
 Normalizing case in a string - eg. WHAT THIS IS. WHAT -> What this is. What
Steve try this.

1 form
1 textbox
1 command button

This code

Option Explicit

'author:hschimanke
Function SentenceCase(Sentence As String)
Dim i As Integer, j As Integer, l As Integer
SentenceCase = Sentence
l = Len(Sentence)
Mid(SentenceCase, 1, 1) = UCase(Mid(SentenceCase, 1, 1))
For i = 1 To l
    If Mid(SentenceCase, i, 1) = "." Then
        For j = i + 1 To l
            If Mid(SentenceCase, j, 1) <> " " Then
                Mid(SentenceCase, j, 1) = UCase(Mid(SentenceCase, j, 1))
                Exit For
            End If
        Next
        i = j
    End If
Next
End Function

Private Sub Command1_Click()
Dim myStr As String
myStr = LCase(Text1)
Text1 = SentenceCase(myStr)
End Sub

HTH
George


Quote:
> Does anyone know if there's a way to normalise the case of a string?  eg.

> WHAT THIS IS. WHAT THIS IS. -> What this is.  What this is.

> I recall that FoxPro has a funtion that does this - called NORMALIZE
> (surprise surprise ;-) )

> Any help would be greatly appreciated.

> Steve



Wed, 27 Oct 2004 10:40:17 GMT  
 Normalizing case in a string - eg. WHAT THIS IS. WHAT -> What this is. What
Steve
If you want to use the question mark also replace this line

If Mid(SentenceCase, i, 1) = "." Then

with this line

If Mid(SentenceCase, i, 1) = "." Or Mid(SentenceCase, i, 1) = "?" Then

George


Quote:
> Steve try this.

> 1 form
> 1 textbox
> 1 command button

> This code

> Option Explicit

> 'author:hschimanke
> Function SentenceCase(Sentence As String)
> Dim i As Integer, j As Integer, l As Integer
> SentenceCase = Sentence
> l = Len(Sentence)
> Mid(SentenceCase, 1, 1) = UCase(Mid(SentenceCase, 1, 1))
> For i = 1 To l
>     If Mid(SentenceCase, i, 1) = "." Then
>         For j = i + 1 To l
>             If Mid(SentenceCase, j, 1) <> " " Then
>                 Mid(SentenceCase, j, 1) = UCase(Mid(SentenceCase, j, 1))
>                 Exit For
>             End If
>         Next
>         i = j
>     End If
> Next
> End Function

> Private Sub Command1_Click()
> Dim myStr As String
> myStr = LCase(Text1)
> Text1 = SentenceCase(myStr)
> End Sub

> HTH
> George



> > Does anyone know if there's a way to normalise the case of a string?
eg.

> > WHAT THIS IS. WHAT THIS IS. -> What this is.  What this is.

> > I recall that FoxPro has a funtion that does this - called NORMALIZE
> > (surprise surprise ;-) )

> > Any help would be greatly appreciated.

> > Steve



Wed, 27 Oct 2004 10:52:11 GMT  
 Normalizing case in a string - eg. WHAT THIS IS. WHAT -> What this is. What

Hey thanks for this guys.  And although the eg. I gave was for normalising
sentences, more than half of the conversions can actually use vbProperCase
strConv.

Steve


Quote:
> Does anyone know if there's a way to normalise the case of a string?  eg.

> WHAT THIS IS. WHAT THIS IS. -> What this is.  What this is.

> I recall that FoxPro has a funtion that does this - called NORMALIZE
> (surprise surprise ;-) )

> Any help would be greatly appreciated.

> Steve



Fri, 29 Oct 2004 07:44:57 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Converting a Upper Case String to Upper and Lower Case

2. Normalize String Spacing

3. Normalize string spacing

4. Select Case - What am I doing wrong?

5. using The Shell Command >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

6. <<<<<<<<ComboBox>>>>>>>>>>>>

7. >>>>>>While Not rst.EOF

8. Conv. String<>BIN<>DEC

9. Conv. String<>BIN<>DEC

10. PSUDOCODE HELP >>>>>>>>>>>

11. user type with string => string

12. VB4-->Access Case Sensitivity

 

 
Powered by phpBB® Forum Software