How would I code VB.NET to accept a string from a text box for example: 89302720304070539803
and then display: 98 03 72 02 03 04 07 35 89 30
Thanks much...
Celldet
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
CelldetPosted Sep 12, 2008, 8:42 AM
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim value As String = textbox1.Text.ToString()
Dim ReturnValue As String = ""
Dim length As Integer = value.Length
While length > 1
Dim cutValue As String = value.Substring(0, 2)
ReturnValue = ReturnValue + " " + Reverse(cutValue)
value = value.Substring(2, value.Length - 2)
length = value.Length
End While
Label1.Text = ReturnValue
End Sub
Public Function Reverse(ByVal str As String) As String
Dim len As Integer = str.Length
Dim arr As Char() = New Char(len - 1) {}
For i As Integer = 0 To len - 1
arr(i) = str(len - 1 - i)
Next
Return New String(arr)
End Function
Blocked AccountPosted Sep 12, 2008, 5:07 AM
Hi,
U can do this by using this code.
protected void Button1_Click(object sender, EventArgs e)
{
string value = textbox1.Text.ToString();
string ReturnValue = "";
int length = value.Length;
while (length > 1)
{
string cutValue = value.Substring(0, 2);
ReturnValue = ReturnValue + " " + Reverse(cutValue);
value = value.Substring(2, value.Length - 2);
length = value.Length;
}
Label1.Text = ReturnValue;
}
public string Reverse(string str)
{
int len = str.Length;
char[] arr = new char[len];
for (int i = 0; i < len; i++)
{
arr[i] = str[len - 1 - i];
}
return new string(arr);
}
Happy Coding!!