dwe0608
asked on
URGENT : String Query
a follow on from my question here
https://www.experts-exchange.com/questions/22079913/URGENT-String-Conversion.html?anchorAnswerId=18064043#a18064043
"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"
https://www.experts-exchange.com/questions/22079913/URGENT-String-Conversion.html?anchorAnswerId=18064043#a18064043
"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"
or
Dim oReg, oMat, oMCol
Dim sData As String
sData = "AnITGuru" & vbCrLf & "AnEXTRAA" & vbCrLf & "IAmEmployedByI.T.S.A"
oReg.IgnoreCase = False
oReg.Global = True
oReg.Pattern = "([A-Z]{1,})([A-Z])"
sData = oReg.Replace(sData, "$1 $2")
oReg.Pattern = "([a-z])([A-Z])"
sData = oReg.Replace(sData, "$1 $2")
MsgBox sData
Dim oReg, oMat, oMCol
Dim sData As String
sData = "AnITGuru" & vbCrLf & "AnEXTRAA" & vbCrLf & "IAmEmployedByI.T.S.A"
oReg.IgnoreCase = False
oReg.Global = True
oReg.Pattern = "([A-Z]{1,})([A-Z])"
sData = oReg.Replace(sData, "$1 $2")
oReg.Pattern = "([a-z])([A-Z])"
sData = oReg.Replace(sData, "$1 $2")
MsgBox sData
please remove these variables
---> oMat, oMCol
---> oMat, oMCol
Sorry ignore all my last posts
Dim oReg
Dim sData As String
sData = "AnITGuru" & vbCrLf & "AnEXTRAA" & vbCrLf & "IAmEmployedByI.T.S.A"
Set oReg = CreateObject("VBScript.Reg Exp")
oReg.IgnoreCase = False
oReg.Global = True
oReg.Pattern = "([A-Z]{1,})([A-Z])"
sData = oReg.Replace(sData, "$1 $2")
oReg.Pattern = "([a-z])([A-Z])"
sData = oReg.Replace(sData, "$1 $2")
MsgBox sData
Dim oReg
Dim sData As String
sData = "AnITGuru" & vbCrLf & "AnEXTRAA" & vbCrLf & "IAmEmployedByI.T.S.A"
Set oReg = CreateObject("VBScript.Reg
oReg.IgnoreCase = False
oReg.Global = True
oReg.Pattern = "([A-Z]{1,})([A-Z])"
sData = oReg.Replace(sData, "$1 $2")
oReg.Pattern = "([a-z])([A-Z])"
sData = oReg.Replace(sData, "$1 $2")
MsgBox sData
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Obadah
ThisIs A TEST
returns
This Is A TES T
notice the space in the last capital letter ....
How can that be resolved so it reads
This Is A TEST
MTIA
Darrin
ThisIs A TEST
returns
This Is A TES T
notice the space in the last capital letter ....
How can that be resolved so it reads
This Is A TEST
MTIA
Darrin
Hello,
The Problem is how should the code tell when to add a space in the end of the string,
f we had
"AnEXTRAA" as the string - it would come out "An EXTRA A" as you see if the Capital letter is the last letter add a space
"ThisIs A TEST" as the string - it would come out "This Is A TEST" ONLY if you treat the last the Capital letter as any other capital letter and not to add a space just for being last
The Problem is how should the code tell when to add a space in the end of the string,
f we had
"AnEXTRAA" as the string - it would come out "An EXTRA A" as you see if the Capital letter is the last letter add a space
"ThisIs A TEST" as the string - it would come out "This Is A TEST" ONLY if you treat the last the Capital letter as any other capital letter and not to add a space just for being last
Private Function SplitIt(strConv As String)
On Error GoTo errChk
strNew = Left(strConv, 1)
For i = 1 To Len(strConv)
Select Case Asc(Mid(strConv, i + 1, 1))
Case 46
strNew = strNew & Mid(strConv, i + 1, 1)
Case 65 To 91
If Asc(Mid(strConv, i + 2, 1)) > 64 And Asc(Mid(strConv, i + 2, 1)) < 92 Then
strNew = strNew & Mid(strConv, i + 1, 1)
Else
strNew = strNew & " " & Mid(strConv, i + 1, 1)
End If
Case 97 To 122
If Asc(Mid(strConv, i + 2, 1)) > 64 And Asc(Mid(strConv, i + 2, 1)) < 92 Then
strNew = strNew & Mid(strConv, i + 1, 1) & " "
Else
strNew = strNew & Mid(strConv, i + 1, 1)
End If
End Select
Next i
SplitIt = strNew
Exit Function
errChk:
If Err.Number = 5 Then
If Asc(Mid(strConv, i + 1, 1)) > 64 And Asc(Mid(strConv, i + 1, 1)) < 92 Then
SplitIt = strNew & " " & Mid(strConv, i + 1, 1)
Else
SplitIt = strNew & Mid(strConv, i + 1, 1)
End If
Exit Function
End If
End Function