Autor Beitrag
vreden123
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 95
Erhaltene Danke: 2



BeitragVerfasst: Mi 25.11.09 21:23 
Hallo gibt es eine preg_match funktion aus PHP für c#?

Kann man auf fögendem PHP code c# code machen?

preg_match("/<title>(.*)<\/title>/i", $page1, $treffer);
$fertig = ereg_replace("s HP","",$treffer[1]);

Kann mir da einer Helfen?
gfoidl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 157
Erhaltene Danke: 19

Win XP
C#, Fortran 95 - Visual Studio
BeitragVerfasst: Mi 25.11.09 21:45 
Hallo,

das verwandteste wäre RegEx. Suche mal danach - es findet sich viel ;)


mfG Günther

_________________
Alle sagten, das geht nicht! Dann kam einer, der wusste das nicht - und hat's gemacht!
vreden123 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 95
Erhaltene Danke: 2



BeitragVerfasst: Mi 25.11.09 21:49 
Ja das habe ich schon aber ich komme damit irgendwie noch nicht kla^^

Ich habe jetzt folgenden Code schon erstellt:
using System.Text.RegularExpressions;
arr = client.DownloadString("http://www.google.de");
Regex r = new Regex("<title>(.*)</title>");
string title = r.Match(arr).Groups[1];
title = title.replace("s HP", "");

Bei den letzten zwei Zeilen mekert er noch.
Einmal das eine Konvertierung in String nicht möglich ist.
Und das String keine Definition für replace hat.

Hoffendlich kann mir da einer Helfen^^
bakachan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 503
Erhaltene Danke: 34

W7 (x64) Ultimate
C# / VB.NET (VS2010 Ultimate)
BeitragVerfasst: Do 26.11.09 09:21 
1. Match ist eine Klasse die mehr Informationen als nur den Text des Ergebnisses beeinhaltet. Den Text an sich rufst du mit Value ab.
ausblenden C#-Quelltext
1:
string title = r.Match(arr).Groups[1].Value;					

2. string hat eine Replace-Funktion man muss nur das R groß schreiben.
ausblenden C#-Quelltext
1:
title = title.Replace("s HP""");					


Das sollte deine Probleme beseitigen.