|
I have the following string format(s) that I am trying to parse.
1-1-1
1-1-2
1-1-10
2-222-1
22-2-31
or
xx-xxx-xx
from which I would like to place xx into an ArrayList, xxx into an ArrayList2 and xx into an ArrayList3. The '-' are delimiters.
Any suggestion would deeply help.
Sincerely,
Tony D. Abel
Have a great coding day.
Regards,
Tony D. Abel
|
|
|
|
|
Simplest for you, although not fastest to execute, would be
char[] delimiters = new char[] {'-'};
string s;
string[] substrings;
substrings = s.Split(delimiters);
Regards,
Jeff Varszegi
|
|
|
|
|
Good day Jeff...
Again thanks for your input. This is what I came up with:
Int32 loadArrays = 0;
char[] delimiters = new char[] {'-'};
string[] substringsBookChapVerID = null;
string strBookChapVerID;
ArrayList chapterList = new ArrayList();
ArrayList verseList = new ArrayList();
///
/// Get the columns primary ID string from the row
///
foreach ( DataRow bibleRow in bibleDataset.Tables[BibleColumnName].Rows )
{
strBookChapVerID = (string) bibleRow[BibleColumnName];
substringsBookChapVerID = strBookChapVerID.Split( delimiters );
///
/// Get the book, chapter and verses substrings
///
foreach ( string number in substringsBookChapVerID )
{
///
/// Save the book, chapter and verses substrings for sorting
///
switch ( loadArrays )
{
case 0:
bookNumber = number;
loadArrays++;
break;
case 1:
if ( number == "0" )
{
loadArrays++;
break;
}
if ( chapterList.Count == 0 )
{ chapterList.Add( number );
loadArrays++;
break;
}
else if ( chapterList.IndexOf( number ) <= -1 )
{
chapterList.Add( number ); loadArrays++;
break;
}
loadArrays++;
break;
case 2:
if ( number.TrimEnd( ' ' ) == "0" )
{
loadArrays = 0;
break;
}
verseList.Add( number.TrimEnd( ' ' ) );
loadArrays = 0;
break;
} // end switch loadArrays
} // end number
} // end bibleRow
I hope you may be able to use this snippet in the future for some project
Have a great coding day.
Regards,
Tony D. Abel
|
|
|
|
|
I got string that was entered by user like this:
"(DC(112, 113) + DN(101, 102)) / CLDC(122, 123)......".
Please help me how to get exactly the "DC(112, 113) and DN(101, 102) and so on" string.
Thanks
Mr Duc Linh Nguyen
|
|
|
|
|
how can i create an array of controls (well, pointers to existing controls that i made on my windows form)
i want to be able to iterate through a collection of existing controls and modify their properties
r -€
|
|
|
|
|
as a side note, can i get an example of how to manage a pointer to a control like i want to have a pointer named pSelectedControl or something which will point to some text box or something
but i get an error something about unsafe blocks
r -€
|
|
|
|
|
So, you're a former C++ developer then?
First up, there's no need to create pointers as controls are reference types : a declaration
Control ctl; creates a reference to a control, not an actual control - it acts like a C++ pointer, in that you can change which actual object it points to, but you can't actually find out the address. Any class (created using the class keyword) in C# is a reference type.
The pointer syntax in C# is for when you want to do some direct bit manipulation of the object - when you want to perform unsafe casting or pointer arithmetic. C# forces you to say, using an unsafe block, when you want to do this - and you also have to pass the /unsafe switch to the compiler. Code compiled /unsafe can't be verified and must run with Full Trust - typically this means it must be copied to the local machine and run from there (this applies to the full Framework - the current version of the Compact Framework does not do security verification in this way).
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Hi Roman. Well, can you just iterate over the Controls collection for your form?
|
|
|
|
|
You can either enumerate (or iterate) over the Controls collection property which already contains your controls that are displayed on a form, or add specific control references (as Mike mentioned, not "pointers").
If you only want to deal with controls of a specific type, for instance, then you could do something like this:
foreach (Control c in Controls)
{
if (c is Button)
{
Button b = (Button)c;
b.Text = "Click me!";
}
} When you enumerate a collection, list, or any other IEnumerable implementation, do not change the underlying enumerable otherwise an exception will be thrown. If you must change the collection or list or whatever, then iterate (the ol' for loop) over the collection or list instead and update your current index accordingly.
There have been times when I wanted to keep a separate list or array (which is a static list, BTW) of certain controls in my form so I could deal with them in a loop as well. You could easily do something like this:
Control[] controls = new Control[] {
this.textBox1,
this.textBox2,
thix.button5
};
foreach (Control c in controls)
for (int i=0; i<controls.Length; i++)
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hey all,
Just wondering if anyone out there has any insight on how to make the text in a Label go vertically, perpendicular to normal text... I can't figure it out and would sure appreciate any help!!
Tks!!!
|
|
|
|
|
You can't do it with a standard label control.
You need to use the Graphics.XXXX classes to draw text vertically.
|
|
|
|
|
you can achieve this by overriding OnPaint of System.Windows.Forms.Label .
Below code will help you in this direction.
protected override void OnPaint(PaintEventArgs e)<br />
{<br />
Graphics g=e.Graphics ;<br />
<br />
StringFormat stringFormat=new StringFormat ();<br />
stringFormat.Alignment =StringAlignment.Center ;<br />
stringFormat.Trimming =StringTrimming.None ;<br />
stringFormat.FormatFlags =StringFormatFlags.DirectionVertical ;<br />
Brush textBrush=new SolidBrush (this.ForeColor );<br />
Matrix storeState=g.Transform ;<br />
<br />
g.RotateTransform(0.0F, MatrixOrder.Append);<br />
g.TranslateTransform(100.0F, 0.0F, MatrixOrder.Append);<br />
g.DrawString (this.Text,this.Font ,textBrush,ClientRectangle ,stringFormat );<br />
g.Transform =storeState;<br />
<br />
}
Do revert back, whether you could achieve the functionality.
(tomorrow and day after tomorrow(28th and 29th) I am on leave)
Regards,
Jay.
|
|
|
|
|
Hello,
How do you append/set subitem within a row?
For example given this listview.
0 1 2 3 4 5
1 2 3 4
In row 2, I'd like to add "5" after the "4." Class ListView supports adding a new row via ListViewItem.
How do you append a new subitem to an exist row?
How do you set the entire row?
Thanks,
Kuphryn
|
|
|
|
|
Here is how I do what you are asking:
<br />
private System.Windows.Forms.ListView myList;
private System.Windows.Forms.ColumnHeader ItemNameCol;
private System.Windows.Forms.ColumnHeader SubItem1Col;<br />
private System.Windows.Forms.ColumnHeader SubItem2Col;<br />
private System.Windows.Forms.ColumnHeader SubItem3Col;<br />
<br />
ItemNameCol.Text = "Name";<br />
SubItem1Col.Text = "Col1";<br />
SubItem2Col.Text = "Col2";<br />
SubItem3Col.Text = "Col3";<br />
<br />
this.myList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[]<br />
{<br />
this.ItemNameCol,<br />
this.SubItem1Col,<br />
this.SubItem2Col,<br />
this.SubItem3Col });<br />
<br />
<br />
ListViewItem item1 = new ListViewItem("ItemName",0);<br />
item1.SubItems.Add( "SubItem1Value" );<br />
item1.SubItems.Add( "SubItem2Value" );<br />
item1.SubItems.Add( "SubItem3Value" ); <br />
<br />
myList.Items.AddRange(new ListViewItem[]{item1});
<br />
Thats how I create a new ListView. To append to a listview, I do the following:
<br />
<br />
item1.SubItems.Add( "New Item Value" );
<br />
ColumnHeader newHeader = new ColumnHeader();
newHeader.Text = "New Header";
<br />
this.myList.Columns.Add(newHeader);
<br />
I hope this helps out. The above code is quite crude, considering I wrote it pretty fast. Let me know if you have any questions about it.
|
|
|
|
|
Okay. Thanks.
Your solution works great for inserting a new column to an existing list. I was thinking more in terms of inserting (setting) text to an existing column.
0 1 2 3 4 5
1 2 3 4 <-- insert text here. column already exists.
Kuphryn
|
|
|
|
|
ListViewItem item = lstProducts.Items.Add("Column1");//<-first
item.SubItems.Add("Column2");
item.SubItems.Add("Column3");
item.SubItems.Add("Column4");
item.SubItems.Add("Column5");
easy?
and if you want to update a previously created column
listName.Items[index].SubItems[subIndex].Text = "";
|
|
|
|
|
Nice!!!
You have to love the [] operator.
Thanks,
Kuphryn
|
|
|
|
|
I used Bitmaps from camera by DirectX in my App . ( I get a frame - analyze and move to the next frame, and so on)
After a long running time I get "exception in system.drawing.dll" in the dispose.
"Object used by other process" ???
If I add "Dispose", I get it sooner.
Thank
Koby
|
|
|
|
|
Does anyone know whether using the conditional operator instead of the if...else clause has a performance hit. In VB.NET, the IIF function is 300% slower than the if...else...end if clause (according to VB.NET in a Nutshell). Also, am I correct in assuming that both true and false expressions are evaluated no matter the result of the conditional expression. For example, in the following:
a = i > j ? b - 10 : c + 20
both 'b - 10' and 'c + 20' are evaluated regardless of the result of 'i > j' (in which case, the conditional operator isn't as efficient as an if...else clause).
Thanks.
|
|
|
|
|
Anonymous wrote:
In VB.NET, the IIF function is 300% slower than the if...else...end if clause (according to VB.NET in a Nutshell).
This information is wrong, or incomplete.
IIF is implemented as a function, and as such, evals both the true and the false part and returns only the true part.
It's easy to see if you run this code:
imports Microsoft.VisualBasic
imports System
imports System.Collections
public module MyModule
function VerySlowFunc(ByVal i as integer) as integer
System.Threading.Thread.Sleep(10 * 1000)
Console.WriteLine("Veryslow called with parameter " + CStr(i))
return i * 2
end function
sub Main
Console.WriteLine(IIF(true, VerySlowFunc(1), VerySlowFunc(2)))
Console.ReadLine()
end sub
end module
This takes 20 seconds to run and print 2 messages, because VB will evaluate both the true and the false part. Change it for an if and the code will take only 10 seconds to run and print only 1 message.
Answering the question: the :? operator on C# is as fast as an if, and does not have the VB.NET behavior.
Due to technical difficulties my previous signature, "I see dumb people" will be off until further notice. Too many people were thinking I was talking about them...
|
|
|
|
|
Anonymous wrote:
In VB.NET, the IIF function is 300% slower than the if...else...end if clause
A lot of this is because VB.NET implements IIf as a function in Microsoft.VisualBasic.dll, which takes two object arguments. Therefore, if you supply integer arguments, they have to be boxed (turned into an object on the heap), then VB has to unbox the result.
The ?: operator in C# is implemented directly in the language and as such doesn't require the boxing operations.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Thanks for your replies. In hindsight, I see that I could have answered this question myself had I put a bit more thought into it. Anyway, thanks again. 
|
|
|
|
|
Hi,
I created a datagrid, bonding with a datatable, with some columns editable. If edit the fields in one row, and cursor stays in the same row,RowState is still "Unchanged", although the datatable has the new value now. RowState will be "Modified" only when I move the cursor to another row. But I want to save my changes to database without moving the cursors to other rows. How should I do it?
BTW, I use :
"if (r.RowState != DataRowState.Unchanged && r.RowState != DataRowState.Deleted)" to judge whether there are changes need to be saved. I don't want to remove this condition because it will cause a lot of unnecessary updates.
Thanks.
|
|
|
|
|
Get the CurrencyManager for the DataGrid and call EndCurrentEdit like so:
CurrencyManager cm = (CurrencyManager)dataGrid1.BindingContext[
dataGrid1.DataSource, dataGrid1.DataMember];
if (cm != null)
cm.EndCurrentEdit();
Also, use DataSet.GetChanges or DataTable.GetChanges and get the Count of rows for the tables. This is a better way of determining changes plus gives you a DataSet of just the changes so that you can pass that to your methods which update the data source (i.e., database). This will also be more efficient if you need to send this DataSet across application boundaries since it won't (potentially) require as much bandwidth since it would have fewer rows.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks a lot! CurrencyManager works fine for my case.
Appreciate for your response!
|
|
|
|