none
how to search for a word in the alphabet? RRS feed

  • Question

  • main:
    alphabet="abcdefghijklmnopqrstuvwxyz"
    TextWindow.WriteLine("Word?")
    word=textwindow.Read()
    run:
    For i=1 To Text.GetLength(word)
      find=Text.GetSubText(alphabet,1,i)
      If find<>word Then
        goto run
      EndIf
    endfor
    TextWindow.WriteLine(find)

    How do i search the variable "alphabet" for the word the user puts in?


    ardiezc_quazhulu was here.

    Monday, July 1, 2013 12:38 AM

Answers

  • How about this?

    alphabet = "abcdefghijklmnopqrstuvwxyz"
    While "True"
      TextWindow.Write("Word? ")
      word = TextWindow.Read()
      If Text.IsSubText(alphabet, word) Then
        TextWindow.WriteLine(word + " is found in alphabet.")
      Else
        TextWindow.WriteLine(word + " is NOT found in alphabet.")
      EndIf
    EndWhile


    Nonki Takahashi

    Friday, July 5, 2013 12:39 PM
    Moderator
  • I don't know if get what you want, but if you want to check if the user only enters letters:

    main:
    
    alphabet="abcdefghijklmnopqrstuvwxyz"
    TextWindow.WriteLine("Word?")
    word=TextWindow.Read()
    
    
    run:
    
    For i=1 To Text.GetLength(word)
      find=Text.GetSubText(word,i, 1)
      If Text.IsSubText(alphabet, find) = "False" Then
        TextWindow.WriteLine("invalid character '" + find + "' entered.")
      EndIf
    endfor

    Monday, July 1, 2013 8:47 AM

All replies

  • I don't know if get what you want, but if you want to check if the user only enters letters:

    main:
    
    alphabet="abcdefghijklmnopqrstuvwxyz"
    TextWindow.WriteLine("Word?")
    word=TextWindow.Read()
    
    
    run:
    
    For i=1 To Text.GetLength(word)
      find=Text.GetSubText(word,i, 1)
      If Text.IsSubText(alphabet, find) = "False" Then
        TextWindow.WriteLine("invalid character '" + find + "' entered.")
      EndIf
    endfor

    Monday, July 1, 2013 8:47 AM
  • How about this?

    alphabet = "abcdefghijklmnopqrstuvwxyz"
    While "True"
      TextWindow.Write("Word? ")
      word = TextWindow.Read()
      If Text.IsSubText(alphabet, word) Then
        TextWindow.WriteLine(word + " is found in alphabet.")
      Else
        TextWindow.WriteLine(word + " is NOT found in alphabet.")
      EndIf
    EndWhile


    Nonki Takahashi

    Friday, July 5, 2013 12:39 PM
    Moderator
  • YES!!! Thank you!

    ardiezc_quazhulu was here.

    Friday, July 5, 2013 4:04 PM
  • I don't know if get what you want, but if you want to check if the user only enters letters:

    main:
    
    alphabet="abcdefghijklmnopqrstuvwxyz"
    TextWindow.WriteLine("Word?")
    word=TextWindow.Read()
    
    
    run:
    
    For i=1 To Text.GetLength(word)
      find=Text.GetSubText(word,i, 1)
      If Text.IsSubText(alphabet, find) = "False" Then
        TextWindow.WriteLine("invalid character '" + find + "' entered.")
      EndIf
    endfor


    This solution could become a TechNet Wiki article and enter the July Small Basic Guru contest: http://social.technet.microsoft.com/wiki/contents/articles/18211.technet-guru-contributions-july-2013.aspx

     

    Great job!


    Ed Price (a.k.a User Ed), SQL Server Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

    Answer an interesting question? Create a wiki article about it!

    Tuesday, July 23, 2013 6:55 AM
    Owner