WCM Forum

WCM Forum (http://www.wcm.at/forum/index.php)
-   Programmierung (http://www.wcm.at/forum/forumdisplay.php?f=17)
-   -   inhalt von variable prüfen (vb) (http://www.wcm.at/forum/showthread.php?t=115476)

Potassium 14.11.2003 17:22

inhalt von variable prüfen (vb)
 
hi leute
ich möchte feststellen ob in einer variable ein bestimmter string enhalten ist. zb: variable1 = "hallo das ist ein test"
if variable2 enthält "das" then
.....
endif
wie mach ich das? :confused:

jak 14.11.2003 17:36

In den meisten Sprachen gibt es indexOf. Dann würde es mit
Dim a as String;
a="test das ist";
if(a.indexOf("das")!=-1)...

gehen. Ob es den Befehl in Vb wirklich gibt weis ich aber nicht.

Jak

Potassium 14.11.2003 17:45

funzt zumindeste so ned in vb? :(
any other ideas?

flinx 14.11.2003 17:50

StrComp ?

jak 14.11.2003 17:54

Vielleicht mit InStr ?

In Vb.net müsste IndexOf gehen.
Zitat:

This code starts at the beginning of 'The weather today is reasonably warm and sunny', because we didn't give a start position, and searches for the word 'warm' in it. If it does not find the word warm in the string, then it will return the value as 0, and you get a message saying '0'. However, if it finds the word, then it returns a number saying where it found the start of the word. In this case, you would see a messagebox saying '32' because the 'w' of warm is 32 characters into the string.

Dim r As String = "The weather today is reasonably warm and sunny"
r = r.IndexOf("warm")

MsgBox(r)
Quelle: http://pscode.com/vb/scripts/ShowCod...=169&lngWId=10

Jak

moorhahn 14.11.2003 18:35

http://msdn.microsoft.com/library/de...vafctinstr.asp
in der msdn-library gucken :)

edit: eigentlich ein wunder das _m3 nicht mit der msdn-library schon zuvorgekommen is :D

jak 14.11.2003 18:52

Wenn man nicht weiß wie die Funktion heißt kann amn aber lang suchen:p

Jak

moorhahn 14.11.2003 21:03

kann man ja zb nach "string" suchen, und verweise durchstöbern :D

darthmaul 15.11.2003 08:11

InStr
 
Probier mal die InStr-Funktion:

Instr("Atari","ri") sollte dann 4 ergeben,
d.h. wenn ein String nicht enthalten ist,
wird 0 zurückgeliefert.

Grüsse
dARTHmAUL

_m3 15.11.2003 11:08

http://support.microsoft.com/default...b;en-us;301264
Zitat:

HOW TO: Match a Pattern Using Regular Expressions and Visual Basic .NET
This article demonstrates how to create and use regular expressions to determine whether strings match certain patterns. Regular expressions allow for easy parsing and matching of strings to a specific pattern. Using the objects available in the RegularExpressions namespace, you can compare a string against a given pattern, replace a string pattern with another string, or retrieve only portions of a formatted string. In this example, we will construct a pattern to validate a e-mail address.
http://msdn.microsoft.com/library/de...xpressions.asp
Zitat:

.NET Framework Regular Expressions
Regular expressions provide a powerful, flexible, and efficient method for processing text. The extensive pattern-matching notation of regular expressions allows you to quickly parse large amounts of text to find specific character patterns; to extract, edit, replace, or delete text substrings; or to add the extracted strings to a collection in order to generate a report.
...


http://www.microsoft.com/downloads/d...displaylang=en
Zitat:

Featured Highlights

* The "Simple Samples" tab is a good introduction to the use of regular expressions. You can see how to find the first occurrence of a number in a string, as well as try out increasingly difficult examples of field validation.
* The "Screen Scrape" tab shows off more advanced uses of regular expressions. You can enter a Web address and view the links or images contained therein. HTML tag attributes are displayed in a ListView control. You can double-click an image to view it, or double-click a link to open Internet Explorer and view the page.
* The "RegEx Tester" tab provides a convenient way for you to experiment with regular expressions. It also demonstrates how to do search and replace and string splitting.
http://www.microsoft.com/downloads/d...displaylang=en
Zitat:

Each textbox inherits a base "RegExTextBox" class. This class is responsible for validating the contents of a text box against a given regular expression.Featured Highlights

* Inheritance is used to modify the behavior of an existing control (the TextBox).
* The controls on this form utilize anchoring so that the form resizes intelligently without the developer having to write any code.
* When the user clicks the "Validate" button on the main form, the code loops through the controls collection to find all the RegExTextBox controls, then casts them to that base type to call their IsValid method.


Alle Zeitangaben in WEZ +2. Es ist jetzt 22:23 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© 2009 FSL Verlag