Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    VBNET - Analizzare se una stringa è un "URL" o una normale stringa di testo...

    Salve a tutti,
    Vorrei creare una textbox, la quale se all'interno ha un url riporta al sito altrimenti cerca su google:
    codice:
    dim x as string = nomefunzione(textboxX.text.tostring)
    If x = "URL" then
      process.start(x)
    else if x = NoURL
      'Cerco su Google la string x
    end if

    Ciò che serve a me, è appunto una Funzione oppure una Soluzione Logica che mi permetta di identificare se ciò che ho scritto è una URL oppure no quindi potrei anche utilizzare una funzione che mi restituisca un boolean... (True è URL, False è Testo).
    Ma sto andando fuori tema... non mi interessa come sintassare l'if ma bensì solo come riconoscere Url o meno (scusate se è la 10548 volta che lo ripeto, ma meglio specificare )


    Qualcuno sa consigliarmi/aiutarmi?

  2. #2
    http://tools.ietf.org/html/rfc3986#section-3.1
    Scheme names consist of a sequence of characters beginning with a
    letter and followed by any combination of letters, digits, plus
    ("+"), period ("."), or hyphen ("-"). Although schemes are case-
    insensitive, the canonical form is lowercase and documents that
    specify schemes must do so with lowercase letters. An implementation
    should accept uppercase letters as equivalent to lowercase in scheme
    names (e.g., allow "HTTP" as well as "http") for the sake of
    robustness but should only produce lowercase scheme names for
    consistency.

    scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
    Quindi, se inizia per una sequenza di lettere/numeri/+/-/. seguito da :// è potenzialmente un URI valido, altrimenti non lo è.
    Puoi fare rapidamente la verifica usando una regex del tipo "^[a-z0-9\+-\.]+://" (in modalità case-insensitive).
    Amaro C++, il gusto pieno dell'undefined behavior.

  3. #3
    Originariamente inviato da MItaly
    Quindi, se inizia per una sequenza di lettere/numeri/+/-/. seguito da :// è potenzialmente un URI valido, altrimenti non lo è.
    Purtroppo le RegEx ancora non le ho capite :'(

    In ogni caso riguardo la tua affermazione, se io provo a scrivere:
    "http://google.com/"
    sarebbe perfetto in quanto rileva che è un URI/URL
    però se ora scrivo:
    "www.google.com/"
    oppure solo
    "google.com"
    questo non verrebbe identificato come sito giusto?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.