Jump to content

Split a character string based on change of character: Difference between revisions

no edit summary
m (→‎{{header|Lua}}: Simply scan difference in reverse order and insert delimiter in place)
No edit summary
Line 1,060:
regsub {, $} $string {} string
puts $string</lang>
 
=={{header|VBA}}==
 
<lang vb>
Option Explicit
 
Sub Split_string_based_on_change_character()
Dim myArr() As String, T As String
 
Const STRINPUT As String = "gHHH5YY++///\"
Const SEP As String = ", "
myArr = Split_Special(STRINPUT)
T = Join(myArr, SEP)
Debug.Print Left(T, Len(T) - Len(SEP))
End Sub
 
Function Split_Special(Ch As String) As String()
'return an array of Strings
Dim tb, i&, st As String, cpt As Long, R() As String
 
tb = Split(StrConv(Ch, vbUnicode), Chr(0))
st = tb(LBound(tb))
ReDim R(cpt)
R(cpt) = st
For i = 1 To UBound(tb)
If tb(i) = st Then
R(cpt) = R(cpt) & st
Else
st = tb(i)
cpt = cpt + 1
ReDim Preserve R(cpt)
R(cpt) = st
End If
Next
Split_Special = R
End Function
</lang>
{{out}}
<pre>g, HHH, 5, YY, ++, ///, \</pre>
 
=={{header|zkl}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.