Re: VB Code for sentence cap
Thread moved from the FAQ forum (which is not the place to post your questions) to the 'VB.Net' forum (based on your previous post being VB2008).
Re: VB Code for sentence cap
I'd suggest looking for the periods rather the spacings or both together. As written languages are riddled with spaces. While the period only signifies the end of a sentence.
You can find the position of any ".", "!", "?" using IndexOf. Using that position work to your right in a loop skipping any spaces that fallow until you find your first letter. Which when you do, you can simply replace it with it's capitalized equivalent. Once complete, you now know to look for your next period and to repeat the process all over again.
Re: VB Code for sentence cap
you're using a lot of legacy code there. try this:
vb Code:
Private Function capitalizeSentences(ByVal s As String) As String
Dim sentences() As String = s.Split(New String() {". ", "? ", "! ", Chr(10) & Chr(10), "." & Chr(10), "?" & Chr(10), "!" & Chr(10), Environment.NewLine & Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
Dim newSentences() As String = DirectCast(sentences.Clone, String())
Dim searchStart As Integer = 0
For x As Integer = 0 To sentences.GetUpperBound(0)
sentences(x) = sentences(x).Trim
newSentences(x) = newSentences(x).Trim
newSentences(x) = newSentences(x).Substring(0, 1).ToUpper & newSentences(x).Substring(1)
Dim start As Integer = s.IndexOf(sentences(x), searchStart)
For c As Integer = start To start + sentences(x).Length - 1
s = s.Remove(c, 1)
s = s.Insert(c, newSentences(x).Substring(c - start, 1))
Next
searchStart += sentences(x).Length + 2
Next
Return s
End Function