Showing posts with label instance. Show all posts
Showing posts with label instance. Show all posts

Wednesday, March 28, 2012

String.Format??

Hi everyone I have a textbox which acts like a counter. I want to format the
number in 4 digits; for instance,
1 -> 0001
10 -> 0010

Is there anyway I can do that?

ThanksTry

foo.ToString("0000").

Cheers,
B

"Hai Nguyen" <haiaggie@.neo.tamu.edu> wrote in message
news:O9rP95e5DHA.1936@.TK2MSFTNGP12.phx.gbl...
> Hi everyone I have a textbox which acts like a counter. I want to format
the
> number in 4 digits; for instance,
> 1 -> 0001
> 10 -> 0010
> Is there anyway I can do that?
> Thanks
Use PadLeft
if your textbox is named Textbox1:

Textbox1.Text.PadLeft
____________________________________
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
DigitallySmooth Inc. | Quick Site Studio
"Hai Nguyen" <haiaggie@.neo.tamu.edu> wrote in message news:O9rP95e5DHA.1936@.TK2MSFTNGP12.phx.gbl...
Hi everyone I have a textbox which acts like a counter. I want to format the
number in 4 digits; for instance,
1 -> 0001
10 -> 0010

Is there anyway I can do that?

Thanks
String.Format("{0:0000}", strMyString);

As always, at least 3 ways to do anything in MS code.

MIke

"Hai Nguyen" <haiaggie@.neo.tamu.edu> wrote in message
news:O9rP95e5DHA.1936@.TK2MSFTNGP12.phx.gbl...
> Hi everyone I have a textbox which acts like a counter. I want to format
the
> number in 4 digits; for instance,
> 1 -> 0001
> 10 -> 0010
> Is there anyway I can do that?
> Thanks

Saturday, March 24, 2012

Stripping out unwanted characters

How can I strip out unwanted characters in a string before updating the
database? For instance, in names & addresses in our client table, we want
only letters and numbers, no punctuation. Is there a way to do this?HI,

Use regular expression to remove unwanted characters and then send the
string to database. Here is a sample code to remove non-alphanumerical
characters from a string.

hoep this will help you...

public static void Main()

{

/*Reg expression to find non-alphanumeric characters*/

string pattern = @."[^A-Za-z0-9]";

/*include System.Text.RegularExpressions name space*/

Regex rgx = new Regex(pattern);

string inputStr = "ab$!Cd&%$gf!";

/*Replace non-alphanumeric characters with space*/

string outputStr = rgx.Replace(inputStr, " ");

Console.WriteLine("Output string:"+ outputStr);

}

Cheers
Vinu

"et" <eagletender2001@.yahoo.com> wrote in message
news:ODVkXK7NGHA.668@.TK2MSFTNGP11.phx.gbl...
> How can I strip out unwanted characters in a string before updating the
> database? For instance, in names & addresses in our client table, we want
> only letters and numbers, no punctuation. Is there a way to do this?
Function StripUnwantedChars(ByVal StringToStrip AsString) AsString
Dim stripped AsString
If StringToStrip <> "" Then
stripped = Regex.Replace(StringToStrip, "<(.|\n)+?>", String.Empty)
Return stripped
Else
Return ""
EndIf
EndFunction

Note : insert all the characters you want to strip inside the quotes.

For example, instead of :
stripped = Regex.Replace(StringToStrip, "<(.|\n)+?>", String.Empty)

use :
stripped = Regex.Replace(StringToStrip, "<!#(.|\n)+?>", String.Empty)

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
===================================
"et" <eagletender2001@.yahoo.com> wrote in message news:ODVkXK7NGHA.668@.TK2MSFTNGP11.phx.gbl...
> How can I strip out unwanted characters in a string before updating the database? For instance,
> in names & addresses in our client table, we want only letters and numbers, no punctuation. Is
> there a way to do this?
Thanks, everyone, that's exactly what I was looking for.

"et" <eagletender2001@.yahoo.com> wrote in message
news:ODVkXK7NGHA.668@.TK2MSFTNGP11.phx.gbl...
> How can I strip out unwanted characters in a string before updating the
> database? For instance, in names & addresses in our client table, we want
> only letters and numbers, no punctuation. Is there a way to do this?

Stripping out unwanted characters

How can I strip out unwanted characters in a string before updating the
database? For instance, in names & addresses in our client table, we want
only letters and numbers, no punctuation. Is there a way to do this?HI,
Use regular expression to remove unwanted characters and then send the
string to database. Here is a sample code to remove non-alphanumerical
characters from a string.
hoep this will help you...
public static void Main()
{
/*Reg expression to find non-alphanumeric characters*/
string pattern = @."[^A-Za-z0-9]";
/*include System.Text.RegularExpressions name space*/
Regex rgx = new Regex(pattern);
string inputStr = "ab$!Cd&%$gf!";
/*Replace non-alphanumeric characters with space*/
string outputStr = rgx.Replace(inputStr, " ");
Console.WriteLine("Output string:"+ outputStr);
}
Cheers
Vinu
"et" <eagletender2001@.yahoo.com> wrote in message
news:ODVkXK7NGHA.668@.TK2MSFTNGP11.phx.gbl...
> How can I strip out unwanted characters in a string before updating the
> database? For instance, in names & addresses in our client table, we want
> only letters and numbers, no punctuation. Is there a way to do this?
>
Function StripUnwantedChars(ByVal StringToStrip AsString) AsString
Dim stripped AsString
If StringToStrip <> "" Then
stripped = Regex.Replace(StringToStrip, "<(.|\n)+?>", String.Empty)
Return stripped
Else
Return ""
EndIf
EndFunction
Note : insert all the characters you want to strip inside the quotes.
For example, instead of :
stripped = Regex.Replace(StringToStrip, "<(.|\n)+?>", String.Empty)
use :
stripped = Regex.Replace(StringToStrip, "<!#(.|\n)+?>", String.Empty)
Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
===================================
"et" <eagletender2001@.yahoo.com> wrote in message news:ODVkXK7NGHA.668@.TK2MSFTNGP11.phx.gbl
..
> How can I strip out unwanted characters in a string before updating the da
tabase? For instance,
> in names & addresses in our client table, we want only letters and numbers
, no punctuation. Is
> there a way to do this?
>
Thanks, everyone, that's exactly what I was looking for.
"et" <eagletender2001@.yahoo.com> wrote in message
news:ODVkXK7NGHA.668@.TK2MSFTNGP11.phx.gbl...
> How can I strip out unwanted characters in a string before updating the
> database? For instance, in names & addresses in our client table, we want
> only letters and numbers, no punctuation. Is there a way to do this?
>

Thursday, March 22, 2012

Strongly Typed dataset

Hello,

I have a typed dataset defined in my project. I am writing a user control
which needs to invoke an instance of that dataset. Problem is that the page
developer only provides the name of the dataset to my user control.
I want my user control to invoke an instance of that dataset from its
"string" representation of the type.
I used type.gettype("Mydatasettype") , but ctype function would not accept
it as a valid type.

Any help is appreciated.Like any other compiled class the generated strongly-typed DataSet can be
accessed by System.Reflection at run-time. The easiest way to do this is
probably with the Activator.CreateInstance(..) method, but I'm fairly
certain you'll have to load the Assembly that has the DataSet in it manually
(if it's not already loaded - you'll have to check for that as well).

Does that help?
Richard
--
C#, .NET and Complex Adaptive Systems:
http://blogs.geekdojo.net/Richard
"Imran" <imran_halim@.hotmail.com> wrote in message
news:On5uAAX4DHA.488@.TK2MSFTNGP12.phx.gbl...
> Hello,
> I have a typed dataset defined in my project. I am writing a user control
> which needs to invoke an instance of that dataset. Problem is that the
page
> developer only provides the name of the dataset to my user control.
> I want my user control to invoke an instance of that dataset from its
> "string" representation of the type.
> I used type.gettype("Mydatasettype") , but ctype function would not accept
> it as a valid type.
> Any help is appreciated.