locked
String into Array RRS feed

  • Question

  • User1168130677 posted

    Let say in .aspx, i have a text box at login menu

    After user key in the text box,

    I want the text box string eg : MICROSOFT

    Now want a Procedure for .net framework 1.1 how to break the string MICROSOFT
    into an array
    Array(1) = M
    Array(2) = I
    Array(3) = C
    Array(4) = R
    Array(5) = O
    Array(6) = S
    Array(7) = O
    Array(8) = F
    Array(9) = T

    Then, check each array for symbol. If found symbol like "$" "!" "^" will quit the procedure.

    Thanks

    Here is what i code;

    [spoiler]
    Dim CompArray() As Char
    Dim i As Integer

    CompArray = txtCompany.Text

            For i = 0 To 14
                If CompArray(i) = "!" Then
                    lblMsg.Text = "* Only allowed alphabet and number entry!"
                    Exit Sub
                End If
            Next

    [/spoiler]

    Wednesday, July 22, 2009 3:22 AM

Answers

  • User-1360095595 posted

    You can look into the ToCharArray method of the string class: http://msdn.microsoft.com/en-us/library/ezftk57x.aspx

    Alternatively, you can simply iterate through the string characters with something like this:

    string text = "test string";
    for (int loop = 0; loop < text.Length; loop++)
    	Response.Write(text[loop] + "<br>");
    

    Of course, instead of the Response.Write you could do your test there...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 22, 2009 9:05 AM
  • User1006193418 posted

    Hi,

    You can simply use String.Contains() method to check the string. Here is an example for you.

    Dim input As String = "MICROSOFT"
    If input.Contains("!") OrElse input.Contains("^") OrElse input.Contains("$") Then
        lblMsg.Text = "Only allowed alphabet and number entry!"
    End If

    Please refer to MSDN for more information about this method at http://msdn.microsoft.com/en-us/library/dy85x1sa.aspx.

    Best Regards,
    Shengqing Yang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 27, 2009 12:02 AM

All replies

  • User-1360095595 posted

    You can look into the ToCharArray method of the string class: http://msdn.microsoft.com/en-us/library/ezftk57x.aspx

    Alternatively, you can simply iterate through the string characters with something like this:

    string text = "test string";
    for (int loop = 0; loop < text.Length; loop++)
    	Response.Write(text[loop] + "<br>");
    

    Of course, instead of the Response.Write you could do your test there...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 22, 2009 9:05 AM
  • User1006193418 posted

    Hi,

    You can simply use String.Contains() method to check the string. Here is an example for you.

    Dim input As String = "MICROSOFT"
    If input.Contains("!") OrElse input.Contains("^") OrElse input.Contains("$") Then
        lblMsg.Text = "Only allowed alphabet and number entry!"
    End If

    Please refer to MSDN for more information about this method at http://msdn.microsoft.com/en-us/library/dy85x1sa.aspx.

    Best Regards,
    Shengqing Yang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 27, 2009 12:02 AM