|
I am using RegEx to find a section of a html document. The document can change, but the format is always the same.
I need RegEx to pull out:
>Name:VisualStudio
Then pull out VisualStudio (VisualStudio is a part of the page that may change)
Is there a way I can do this by passing strings to a function?
Thanks for any, and all help!
|
|
|
|
|
Let's have a look at your code, then, and perhaps you can tell what's the problem with it?
---
b { font-weight: normal; }
|
|
|
|
|
I don't have any code yet as I haven't ever worked with RegEx. I have heard it is difficult, i want to learn but I don't even know the structure.
|
|
|
|
|
private static void InterpretData(string szProfile)
{
Regex rxFind = new Regex(@">Name <szcharname>)");
MatchCollection matches = rxFind.Matches(szProfile);
foreach (Match match in matches)
{
if (match.Length != 0)
{
Console.WriteLine("Character Name: {0}", match.Groups["szcharname"]);
}
}
Console.WriteLine("RegEx'ed'");
Console.ReadLine();
}
It isn't finding a match. See anything?
I think that matches assumes you know exaclty the formet of the string. How do I FIND the string, then match it? Is there a better way?
-- modified at 20:30 Tuesday 7th February, 2006
|
|
|
|
|
You have specified that you want to find a question mark. That will match exactly one occurance of that character, nothing else.
Use a period to match any character (except line break), use a plus sign to specify that it should occur one or more times, and add a question mark after the plus sign to specify that it should match as few times as possible.
Regex rxFind = new Regex(@">Name:</td><td>(.+?)</td>");
---
b { font-weight: normal; }
|
|
|
|
|
I need to find the data between where the ? was. How do I do that?
|
|
|
|
|
string text="";
Regex x = new Regex(">Name:</td><td>(.+?)</td>");
foreach (Match m in x.Matches(text))
{
if (m.Groups.Count > 1)
{
Console.WriteLine(m.Groups[1].Value);
}
}
|
|
|
|
|
string text = szText;
//Get text here
//Parse
Regex x = new Regex(">Name lt;charactername>)");
foreach (Match match in x.Matches(text))
{
if (match.Length != 0)
{
Console.WriteLine("Hello: {0}", match.Groups["charactername"]);
}
}
Console.WriteLine("RegEx'ed'");
Its not working!
|
|
|
|
|
Ok, I am pulling a page off the internet. I want to first grab this out of the HTML:
>Name:Whatcha
Then grab Whatcha out of that.
I will not know that the name will be Whatcha everytime, nor will i know the length. It will always be a string, and in the same spot.
Help please. I don't know how to do this at all. I learn by example. Thanks for your time.
|
|
|
|
|
Ok my problem lies in this:
Regex rxFind = new Regex(">Name <szchar>)", RegexOptions.IgnoreCase);
It has something to do with the (?<szchar>), how do I properly format this so that I can get whatever information is there?
|
|
|
|
|
I already answered this. There is no use to rephrase the question over and over if you never read the answers.
---
b { font-weight: normal; }
|
|
|
|
|
No, I read your response. You were wrong. ? starts the query. I forgot to include what I was looking for. The correct statement is this:
Regex rxFind = new Regex(">Name <szchar>[a-z]+)", RegexOptions.IgnoreCase);
I forgot to say I was looking for an alphanumeric word ([a-z]+).
|
|
|
|
|
for alphanumeric your [a-z] should probably have been [A-Za-z0-9]
|
|
|
|
|
So you want to find a string that starts with a question mark? Like ">Name:</td><td>?Jane</td>"?
---
b { font-weight: normal; }
|
|
|
|
|
Hi I try to create a makecert like program in order to generate X.509 certificates (which extends PKCS6).
So is there any open source version or any source code that might help?
Thanks
|
|
|
|
|
How can I extract a dataset to an Excel Spread Sheet?
|
|
|
|
|
Hi everybody,
I'm trying to develop an application that will send some type of alert(text message) to a cell phone when a certain event occurs. Where do I start? Where can I find more information on doing this? I'm using C# in MS VS.NET 2003
|
|
|
|
|
|
hi i want to set property of controls in one form from other forms and i test all ways (for example public modefiers,define property that return control.property , ...) and don't gave result .
please help me ...
|
|
|
|
|
set the modifiers on textbox1 to public.
if this doesn't fix the problem, post the code you are using.
|
|
|
|
|
hi thanks to your instruction but don't get result for change textbox1 modefier to public . here is my code :
//in form 1 (modifier of textbox1 is public):
this.textbox1.text = "hello";
//in form 2 (for example):
Form 1 f = new Form1();
//this line should be display Form1.textbox1.text in Form2.label1.text but doesn't it :
this.label1.text = f.textbox1.text;
|
|
|
|
|
this.textbox1.Text = "hello"; needs to be in the constructor of Form1, otherwise textbox1.text will contain the default value "" (nothing) until it is assigned to. Also, the textbox needs to be initialized before this happens.
You might also try telling the label to redraw itself after its text value gets reassigned: this.label1.Invalidate();
public System.Windows.Forms.TextBox textbox1;
public Form1()
{
this.textbox1 = new System.Windows.Forms.TextBox();
...
this.textbox1.Text = "hello";
}
Form1 f = new Form1();
this.label1.Text = f.textbox1.Text;
this.label1.Invalidate();
To see if things are working, you can try this:
public System.Windows.Forms.TextBox textbox1;
public Form1()
{
this.textbox1 = new System.Windows.Forms.TextBox();
...
}
Form1 f = new Form1();
f.textbox1.Text="hello"
this.label1.Text = f.textbox1.Text;
this.label1.Invalidate();
|
|
|
|
|
hi,
i'm trying to update a database by a datatable through a stored prcedure like that :
private void button2_Click(object sender, System.EventArgs e)<br />
{<br />
Cursor =Cursors.WaitCursor; <br />
if(MessageBox.Show("are you sure you want to Delete","Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2) == DialogResult.Yes)<br />
{<br />
dataSet6.Tables["SELECT_STAFF_REAL"].Rows[x].Delete();<br />
try<br />
{<br />
DataTable table1=dataSet6.Tables["SELECT_STAFF_REAL"].GetChanges();<br />
if(table1!=null) <br />
{<br />
sqlDataAdapter6.Update(table1); <br />
dataSet6.Tables["SELECT_STAFF_REAL"].AcceptChanges();<br />
<br />
gridEx1.DataSource=dataSet6.Tables["SELECT_STAFF_REAL"];<br />
}<br />
}<br />
catch(Exception err)<br />
{<br />
MessageBox.Show(err.Message);<br />
}<br />
}<br />
rowCount--;<br />
Cursor =Cursors.Default;<br />
}
and this is the stored procedure:
CREATE procedure select_staff_real @job varchar(20) ,@field varchar(20)<br />
as<br />
SELECT STAFF.S_SSN, STAFF.S_NAME AS Name, STAFF.S_USER_NAME, STAFF.S_PASS_WORD, STAFF.S_E_MAIL AS [E-Mail], STAFF.S_ADDRESS, STAFF.S_CITY, STAFF.S_PHONE_NUMBER AS [Home Phone], STAFF.S_MOBILE_NUMBER AS [Mobile Phone], STAFF.S_SALARY, STAFF.S_COMMENT, DESIGNATION.D_ID, DESIGNATION.D_TYPE AS Designation, STAFF.S_DESIGNATION_ID FROM STAFF INNER JOIN DESIGNATION ON STAFF.S_DESIGNATION_ID = DESIGNATION.D_ID<br />
<br />
where d_type like '%'+@job+'%' and s_name like '%' +@field +'%'<br />
GO
and i have error that tells me that the parameter @job must be assigned to a value.
so my question is what is the reason of that error.
or how to update a datasource by using stored procedure
thanx
|
|
|
|
|
I can successufully add a context menu along with items and appropriate actions to a datagrid. However, when I left click "into" a cell and then right click the same cell, the standard menu (COPY, PASTE, etc) appears. Only by right clicking the grid (anywhere other than the cell left-clicked) does my context menu appear. I suppose that the underlying control is being exposed which is tied to the system's context menu.
My question is: Can I get around this somehow? Can I somehow bind my context menu to the underlying control?
OrbeaOrca
|
|
|
|
|
Hello everyone, Ive been trying to get my program to function for quite some time now and havent been able to get any clear answers. its a simple practice app basically, when I click a button on my form, I want the app to press a button in another form. that simple. seemed like it at least, but when I try to use this it doesnt work.
int a = Win32.FindWindow(txtClassName2.Text, Title.Text);
int b = Win32.SendMessage(a, Win32.BM_CLICK, 0, 0);
when I replace Win32 with Win32API, then theres a problem with SendMessage not being part of the current selection, also there is a problem with FindWindow with Win32API. FindWindowEx doesnt work either. When I use Win32, they work work but BM_CLICK doesnt work. its like I have to choose which problem to go with, I havent been able to figure this out. this is actually the whole code in the form.cs file:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace test
{
public partial class Form1 : Form
{
[DllImport("user32", EntryPoint = "GetNextWindow")]
public static extern int
GetWindow(IntPtr hwnd, int wFlag);
public Form1()
{
InitializeComponent();
}
public class Win32
{
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_CLOSE = 0xF060;
public const int BM_CLICK = 0xF5;
[DllImport("user32.dll")]
public static extern int FindWindow(string lpClass, string lpWindow);
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);
}
private void button1_Click(object sender, EventArgs e)
{
int hWnd;
//Thread.Sleep(5000);
if ((txtWindowCaption.Text == "") && (txtClassName.Text == ""))
{
hWnd = Win32API.FindWindowAny(0, 0);
}
else if ((txtWindowCaption.Text == "") && (txtClassName.Text != ""))
{
hWnd = Win32API.FindWindowNullWindowCaption(txtClassName.Text, 0);
}
else if ((txtWindowCaption.Text != "") && (txtClassName.Text == ""))
{
hWnd = Win32API.FindWindowNullClassName(0, txtWindowCaption.Text);
}
else
{
hWnd = Win32API.FindWindow(txtClassName.Text, txtWindowCaption.Text);
}
if (hWnd == 0)
{
MessageBox.Show("Specified window is not running.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
// Set the window foreground.
Win32API.SetForegroundWindow(hWnd);
// if window is minimized, simply restore, otherwise show it. Notice the
// declaration of Win32API.IsIconic defines the return value bool
// allowing .NET to marshall the integer value to a bool.
if (Win32API.IsIconic(hWnd))
{
Win32API.ShowWindow(hWnd, Win32API.SW_RESTORE);
}
else
{
Win32API.ShowWindow(hWnd, Win32API.SW_SHOW);
}
int a = Win32.FindWindow(txtClassName2.Text, Title.Text);
int b = Win32.SendMessage(a, Win32.BM_CLICK, 0, 0);
}
}
}
}
anyone got any advice? thanks
|
|
|
|