Solved

URGENT: String Conversion

Posted on 2006-12-01
10
239 Views
Last Modified: 2010-04-30
Hi Guys

(1) I have a string as follows:

ThisIsAnExampleString

I am looking for a function to convert that string to:

This Is An Example String

(2) I also have a string as follows:

This_Is_An_Example_String

I would like to convert that string to the same as in my first question ... I can do this using the Replace Function in VB6; but I would like to use one function to do both conversions ....

Hoping my question is clear

MTIA


Darrin


0
Comment
Question by:dwe0608
10 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 18058425
Passing either instance of strT returns the string you desire:

strT = "ThisIsAnExampleString"
strT = "This_Is_An_Example_String"
MsgBox SplitIt(strT)
End Sub

Private Function SplitIt(strConv As String)
On Error Resume Next
    strNew = Left(strConv, 1)
    For i = 1 To Len(strConv)
      Select Case Asc(Mid(strConv, i + 1, 1))
        Case 65 To 91
          strNew = strNew & " " & Mid(strConv, i + 1, 1)
        Case 97 To 122
          strNew = strNew & Mid(strConv, i + 1, 1)
      End Select
    Next i
    SplitIt = strNew
End Function
0
 
LVL 11

Expert Comment

by:bingie
ID: 18058430
Private Sub Form_Load()
    MsgBox convertString("ThisIsAnExampleString")
    MsgBox convertString("This_Is_An_Example_String")
End Sub

Private Function convertString(str As String) As String

    If InStr(str, "_") > 0 Then
        str = Replace(str, "_", " ")
        Exit Sub
    End If
   
    'Since capital letters are ascii 65 to 90,
    'we can check for that
    Dim cnt As Integer
    For cnt = 2 To Len(str) 'Start at the second letter
        If (Asc(Mid(str, cnt, 1)) >= 65 And Asc(Mid(str, cnt, 1)) <= 90) Then
            'The letter is a capital
            str = Mid(str, 1, cnt - 1) & " " & Mid(str, cnt, 1) & Mid(str, cnt + 1)
            cnt = cnt + 2
        End If
    Next
       
    convertString = str

End Function
0
 
LVL 1

Author Comment

by:dwe0608
ID: 18058489
Guy, both answers work ... brilliant, now, how could we resolve the string if it were

This_IsAnExample_String

ie its combination of both questions ...

MTIA

Darrin

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 67

Expert Comment

by:sirbounty
ID: 18058503
My solution should work in that case as well...
0
 
LVL 1

Author Comment

by:dwe0608
ID: 18058521
Thasnks for the prompt help guys ... muchly appreciated ....
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 18059662
You could use API to check the bit of the character, if your format of the start of a new word is a capital letter than it would work perfectly. Let me know if you would like to see an example using this method.
0
 
LVL 1

Author Comment

by:dwe0608
ID: 18061324
Always willing to see examples egl1044 ....

MTIA

Darrin
0
 
LVL 1

Author Comment

by:dwe0608
ID: 18062922
Sirbounty

If I have a string, AnITGuru .... it would under the current rules of the function be broken down to

An I T Guru

is it possible to change the coding so if we have two or more capitals in a row it only seperates the last one ?

So if we had

AnEXTRAA as the string - it would come out

An EXTRA A

And perhaps if string were "IAmEmployedByI.T.S.A" - it sould say

I Am Employed By I.T.S.A

I am willing to post another question - but did know how to follow on from here ... so if you have the answer, I will post a question for you for 500 points ...

MTIA

Darrin
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18064043
The first request wouldn't be too terrible complicated, but the others add a bit more to the logic.
You can open a new question, and in the body of the question, paste the link to this question, stating it's a followup.
I'll see if I can come up with something to do what you ask...
0
 
LVL 1

Author Comment

by:dwe0608
ID: 18064975
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA open file from excel cell 4 44
message box in access 4 51
Child Form in front 4 49
how to loop through and process two columns in excel 8 22
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question