473,385 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Recursive function to change Char's in a String to Upper/lower

Hello,

I'm looking for a function for converting the input to a regular text.
Example: when the input is "aBCdefgHI jkLM ooPP" the return value of the
function should be "Abcdefghi Jklm Oopp"

Thanks in advance,

Anita

Nov 21 '05 #1
7 3239
GysAnn wrote:
I'm looking for a function for converting the input to a regular text.
Example: when the input is "aBCdefgHI jkLM ooPP" the return value
of the function should be "Abcdefghi Jklm Oopp"

Dim oldText As String
Dim newText As String

'Get the original text
oldText = "aBCdefgHI jkLM ooPP"

'Convert to Proper Case
newText = StrConv(oldText, VbStrConv.ProperCase)

'Remove any double-spaces
Do While InStr(newText, " ") > 0
newtext = replace(newtext," "," ")
Loop

'All done
MsgBox(newText)

--

(O)enone

Nov 21 '05 #2

"Oenone" <no***@nowhere.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
GysAnn wrote:
I'm looking for a function for converting the input to a regular text.
Example: when the input is "aBCdefgHI jkLM ooPP" the return value
of the function should be "Abcdefghi Jklm Oopp"

Dim oldText As String
Dim newText As String

'Get the original text
oldText = "aBCdefgHI jkLM ooPP"

'Convert to Proper Case
newText = StrConv(oldText, VbStrConv.ProperCase)

'Remove any double-spaces
Do While InStr(newText, " ") > 0
newtext = replace(newtext," "," ")
Loop

'All done
MsgBox(newText)


StrConv with ProperCase enum will only uppercase the first letter in each
word in the phrase..

so...

Sub Main()
Dim text As String = "aBCdefgHI jkLM ooPP"

Console.WriteLine("Before ReCasing : " & text)
text = ReCaseString(text)
Console.WriteLine("After ReCasing : " & text)
text = RemoveDblSpaces(text)
Console.WriteLine("After Removing DblSpaces: " & text)
End Sub

Private Function ReCaseString(ByVal Text As String) As String
Dim chars As Char() = Text.ToCharArray()
Text = String.Empty

For Each ch As Char In chars
If Char.IsLower(ch)
ch = Char.ToUpper(ch)
Else
ch = Char.ToLower(ch)
End If

Text &= ch
Next

Return Text
End Function

Private Function RemoveDblSpaces(ByVal Text As String) As String
While Text.IndexOf(Space(2)) > 0
Text = Text.Replace(Space(2), Space(1))
End While

Return Text
End Function
Nov 21 '05 #3
Thanks, but i must be on an recursive way like :

myString = "aBCdefgHI jkLM ooPP" '(from InputBox by example)
myCorrectedStr = fncCorrectInput(myString)

Private Function fncCorrectInput(ByVal myString as String) As String
If ....
Return....
Else
Return .....(?) ...... & fncCorrectInput(myParameter)
End If
End Function
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #4
The function has to loop thrue the string in a recursive way (= no loops
Do... / For....) like :
myString = "aBCdefgHI jkLM ooPP" '(from InputBox by example)
myCorrectedStr = fncCorrectInput(myString)
' my corrected string is now : "Abcdefghi Jklm Oopp"

Private Function fncCorrectInput(ByVal myString as String) As String
If ....
Return....
Else
Return .....(?) ...... & fncCorrectInput(myParameter)
End If
End Function

"Oenone" <no***@nowhere.com> schreef in bericht
news:%2***************@TK2MSFTNGP10.phx.gbl...
GysAnn wrote:
I'm looking for a function for converting the input to a regular text.
Example: when the input is "aBCdefgHI jkLM ooPP" the return value
of the function should be "Abcdefghi Jklm Oopp"

Dim oldText As String
Dim newText As String

'Get the original text
oldText = "aBCdefgHI jkLM ooPP"

'Convert to Proper Case
newText = StrConv(oldText, VbStrConv.ProperCase)

'Remove any double-spaces
Do While InStr(newText, " ") > 0
newtext = replace(newtext," "," ")
Loop

'All done
MsgBox(newText)

--

(O)enone

Nov 21 '05 #5
GysAnn,
The function has to loop thrue the string in a recursive way (= no loops Sounds like a homework assignment.

(O)enone's method seems to be the easiest way to solve this problem.

I wish you well in the class!

Hope this helps
Jay

"GysAnn" <be****@NOSPAMtelenet.be> wrote in message
news:CH*********************@phobos.telenet-ops.be... The function has to loop thrue the string in a recursive way (= no loops
Do... / For....) like :
myString = "aBCdefgHI jkLM ooPP" '(from InputBox by example)
myCorrectedStr = fncCorrectInput(myString)
' my corrected string is now : "Abcdefghi Jklm Oopp"

Private Function fncCorrectInput(ByVal myString as String) As String
If ....
Return....
Else
Return .....(?) ...... & fncCorrectInput(myParameter)
End If
End Function

"Oenone" <no***@nowhere.com> schreef in bericht
news:%2***************@TK2MSFTNGP10.phx.gbl...
GysAnn wrote:
I'm looking for a function for converting the input to a regular text.
Example: when the input is "aBCdefgHI jkLM ooPP" the return value
of the function should be "Abcdefghi Jklm Oopp"

Dim oldText As String
Dim newText As String

'Get the original text
oldText = "aBCdefgHI jkLM ooPP"

'Convert to Proper Case
newText = StrConv(oldText, VbStrConv.ProperCase)

'Remove any double-spaces
Do While InStr(newText, " ") > 0
newtext = replace(newtext," "," ")
Loop

'All done
MsgBox(newText)

--

(O)enone


Nov 21 '05 #6
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schrieb:
The function has to loop thrue the string in a recursive way (= no loops


Sounds like a homework assignment.


Looks like a /bad/ example for learning where to use recursion... ;-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #7
Herfried,
LOL, that too!!!

Jay

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:Oa**************@TK2MSFTNGP15.phx.gbl...
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schrieb:
The function has to loop thrue the string in a recursive way (= no loops


Sounds like a homework assignment.


Looks like a /bad/ example for learning where to use recursion... ;-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #8

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

Similar topics

1
by: f | last post by:
Suppose I have a xml <class> <Name>Good</Name> <Name>bad</Name> </class> I hava the xsl <xsl:template match="Class">
2
by: Ebi | last post by:
Hi I'm writing a project in C++ borland 5; and I need a function that get a string or char* variable and convert all of the small letters to the capital. please help me. -- Sincerely Yours...
1
by: Nathon | last post by:
I have a .NET web app (.NET Nuke) and then I have a virtual directory under that app with a completely independent .NET web app. However, I get the following error when executing the second web...
15
by: phil-news-nospam | last post by:
This question is borderline between language and programming, but I want to focus more on the language standards issue, rather than the programming issue, so I am posting here. I have a number...
12
by: AMT2K5 | last post by:
Hello. I have the following function titled cleanSpace that recieves a string and cleans it up. My program passes a string to the function via "cleanSpace(c)". The function works the first time...
11
by: randomtalk | last post by:
hi, i have the following recursive function (simplified to demonstrate the problem): >>> def reTest(bool): .... result = .... if not bool: .... reTest(True) .... else: .... print...
3
by: bob | last post by:
In vb6 you could say s = Format(s, "!") to force text to upper case in the format function. I've searched the vb.net help system and can't find any help on formatting text. There's plenty of help...
26
by: MLH | last post by:
How would I modify the following to achieve a 2-dimensional array? Dim MyWeek, MyDay MyWeek = Array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun") ' Return values assume lower bound set to 1...
15
by: ssecorp | last post by:
if i want to make a string downcase, is upper().swapcase() the onyl choice? there is no downer() ?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.