Особенности работы со строковыми переменными в VB. Часть 2

Листинг 2. Варианты реализация функции StrReverse традиционными средствами Basic

Function ReverseString(sSource As String) As String
	Dim sReverse As String
	Dim i%
	For i = Len(sSource) To 1 Step -1
		sReverse = sReverse & Mid$(sSource, i, 1)
	Next i
	ReverseString = sReverce
End Function

Public Function ReverseStringMy(Source$) As String
	Dim Reverse$, i%, j%
	Reverse$ = Space$(Len(Source$))
	For i = Len(Source$) To 1 Step -1
		j = j + 1
		Mid$(Reverse$, j, 1) = Mid$(Source, i, 1)
	Next
	ReverseStringMy = Reverse$
End Function

Public Function ReverseStringByteMy(Source$) As String
	' revised procedure (VBPJ 12'98, p.129)
	Dim bString() As Byte, bString2() As Byte
	Dim i%, j%, iLen%
	'
	bString = Source$
	iLen = Len(Source$) * 2 - 1
	ReDim bString2(iLen)
	For i = iLen To 0 Step -2
		bString2(j) = bString(i - 1):
		bString2(j + 1) = bString(i)
	j = j + 2
	Next i
	ReverseStringByteMy = bString2
End Function

возврат


Наш канал на Youtube

1999 1 2 3 4 5 6 7 8 9 10 11 12
2000 1 2 3 4 5 6 7 8 9 10 11 12
2001 1 2 3 4 5 6 7 8 9 10 11 12
2002 1 2 3 4 5 6 7 8 9 10 11 12
2003 1 2 3 4 5 6 7 8 9 10 11 12
2004 1 2 3 4 5 6 7 8 9 10 11 12
2005 1 2 3 4 5 6 7 8 9 10 11 12
2006 1 2 3 4 5 6 7 8 9 10 11 12
2007 1 2 3 4 5 6 7 8 9 10 11 12
2008 1 2 3 4 5 6 7 8 9 10 11 12
2009 1 2 3 4 5 6 7 8 9 10 11 12
2010 1 2 3 4 5 6 7 8 9 10 11 12
2011 1 2 3 4 5 6 7 8 9 10 11 12
2012 1 2 3 4 5 6 7 8 9 10 11 12
2013 1 2 3 4 5 6 7 8 9 10 11 12
Популярные статьи
КомпьютерПресс использует