[ASP] string checken op bepaalde tekens

Pagina: 1
Acties:
  • 109 views sinds 30-01-2008
  • Reageer

  • KoeKk
  • Registratie: September 2000
  • Laatst online: 14-09 19:20
Ik krijg een string vanuit een formulier en van daaruit bouw ik een redelijk complexe SQL query op.
De string kan 1 getal bevatten of meerdere gescheiden op Komma's

zo dus: "6, 8, 3, 5"

hoe kan ik controleren of deze string komma's bevat?

  • Nielsz
  • Registratie: Maart 2001
  • Niet online
ik geloof 'instr' of instring ofzo, maar dat zal vast in de manual staan.

  • KoeKk
  • Registratie: September 2000
  • Laatst online: 14-09 19:20
ok, met deze hint kom ik wel wat verder, thnx

  • Basszje
  • Registratie: Augustus 2000
  • Laatst online: 17:07

Basszje

Reisvaap!]

Waarom wil je dat weten trouwens?
Je kan toch ook gewoon je query maken met komma gescheiden getallen dus :

[query] + where id in ( 1,3,4,5 )

Als je het toch wilt weten kan je split gebruiken en dan kijken hoeveel waardes in je array zitten ( dan weet je het ) .

Anders moet je ff bij devguru checken voor andere functies.

Beware of listening to the imposter; you are undone if you once forget that the fruits of the earth belong to us all, and the earth itself to nobody.


Verwijderd

Met inStr kun je kijken of er komma's in voorkomen, en met split(jouwexpressie, ",") krijg je een array terug met alle getallen die er in staan die gescheiden worden door komma's.

  • Basszje
  • Registratie: Augustus 2000
  • Laatst online: 17:07

Basszje

Reisvaap!]

Op maandag 10 september 2001 13:05 schreef EvilMarty het volgende:
Met inStr kun je kijken of er komma's in voorkomen, en met split(jouwexpressie, ",") krijg je een array terug met alle getallen die er in staan die gescheiden worden door komma's.
I know. Ik geef toe , een beetje omslachtig maar het werkt wel. :)

[ed]
Maar ik pleur dat soort dingen altijd gewoon in my query ( na de nodige checks of course ) ,dus ik zie het probleem niet zo
[/ed]

Beware of listening to the imposter; you are undone if you once forget that the fruits of the earth belong to us all, and the earth itself to nobody.


  • misfire
  • Registratie: Maart 2001
  • Laatst online: 06-09 13:50
Met de InStr functie kun je op strings binnen een string zoeken:

InStr Function
Returns the position of the first occurrence of one string within another.

InStr([start, ]string1, string2[, compare])

Arguments
start

Optional. Numeric expression that sets the starting position for each search. If omitted, search begins at the first character position. If start contains Null, an error occurs. The start argument is required if compare is specified.

string1

Required. String expression being searched.

string2

Required. String expression searched for.

compare

Optional. Numeric value indicating the kind of comparison to use when evaluating substrings. See Settings section for values. If omitted, a binary comparison is performed.

Settings
The compare argument can have the following values:

Constant Value Description
vbBinaryCompare 0 Perform a binary comparison.
vbTextCompare 1 Perform a textual comparison.


Return Values
The InStr function returns the following values:

If InStr returns
string1 is zero-length 0
string1 is Null Null
string2 is zero-length start
string2 is Null Null
string2 is not found 0
string2 is found within string1 Position at which match is found
start > Len(string2) 0


Remarks
The following examples use InStr to search a string:

Dim SearchString, SearchChar, MyPos
SearchString ="XXpXXpXXPXXP" ' String to search in.
SearchChar = "P" ' Search for "P".
MyPos = Instr(4, SearchString, SearchChar, 1) ' A textual comparison starting at position 4. Returns 6.
MyPos = Instr(1, SearchString, SearchChar, 0) ' A binary comparison starting at position 1. Returns 9.
MyPos = Instr(SearchString, SearchChar) ' Comparison is binary by default (last argument is omitted). Returns 9.
MyPos = Instr(1, SearchString, "W") ' A binary comparison starting at position 1. Returns 0 ("W" is not found).
Note The InStrB function is used with byte data contained in a string. Instead of returning the character position of the first occurrence of one string within another, InStrB returns the byte position.

Requirements
Version 1

See Also
InStrRev Function

PS: Dit staat gewoon in de MSDN en op een miljard andere asp sites hoor!

  • KoeKk
  • Registratie: September 2000
  • Laatst online: 14-09 19:20
ok, thnx allemaal

als ik een query maak na een where statement kan dat dus niet:

where k_id = 1, 3, 4 AND bladiebla

dat moet dus worden Where k_id = 1 AND k_id = 3 enz, enz.

<edit>
het is zelfs simpeler... kan ook gewoon met Replace() |:(

iig bedankt voor de moeite
</edit>
Pagina: 1