Wednesday, March 28, 2012
Substring
letters separated into two groups by a dash (-). I want to obtain the
letters before the dash. I use the following code. Strangely, when the
array has a value of "MOD-AS" Label3 displays "3" while Label4 displays -1.
What's going on ? What is changing the value of variable mn ? Thanks,
Jim
int i = 32;
string s1;
string s2;
s1 = Ante_Arr[i];
int mn = s1.IndexOf("-");
Label3.Text = mn.ToString(); // the displayed value is 3
try
{
s2 = s1.Substring(1, mn); // throws an error: length can not be less
than zero
}
catch
{
Label4.Text = mn.ToString(); // the displayed value is -1
}Maybe it's scope?
Put the int mn = s1.IndexOf("-"); line into the try block, or take a look at
the value of mn before the s2 = s1.Substring(1, mn); line.
"Jim McGivney" <mcgiv1@.no-spam.sbcglobal.net> wrote in message
news:O7EM879dGHA.3348@.TK2MSFTNGP03.phx.gbl...
> In an aspx (asp2.0) page in C# I have a string array. The array contains
> letters separated into two groups by a dash (-). I want to obtain the
> letters before the dash. I use the following code. Strangely, when the
> array has a value of "MOD-AS" Label3 displays "3" while Label4
> displays -1.
> What's going on ? What is changing the value of variable mn ? Thanks,
> Jim
> int i = 32;
> string s1;
> string s2;
> s1 = Ante_Arr[i];
> int mn = s1.IndexOf("-");
> Label3.Text = mn.ToString(); // the displayed value is 3
> try
> {
> s2 = s1.Substring(1, mn); // throws an error: length can not be less
> than zero
> }
> catch
> {
> Label4.Text = mn.ToString(); // the displayed value is -1
> }
>
Substring
letters separated into two groups by a dash (-). I want to obtain the
letters before the dash. I use the following code. Strangely, when the
array has a value of "MOD-AS" Label3 displays "3" while Label4 displays -1.
What's going on ? What is changing the value of variable mn ? Thanks,
Jim
int i = 32;
string s1;
string s2;
s1 = Ante_Arr[i];
int mn = s1.IndexOf("-");
Label3.Text = mn.ToString(); // the displayed value is 3
try
{
s2 = s1.Substring(1, mn); // throws an error: length can not be less
than zero
}
catch
{
Label4.Text = mn.ToString(); // the displayed value is -1
}Maybe it's scope?
Put the int mn = s1.IndexOf("-"); line into the try block, or take a look at
the value of mn before the s2 = s1.Substring(1, mn); line.
"Jim McGivney" <mcgiv1@.no-spam.sbcglobal.net> wrote in message
news:O7EM879dGHA.3348@.TK2MSFTNGP03.phx.gbl...
> In an aspx (asp2.0) page in C# I have a string array. The array contains
> letters separated into two groups by a dash (-). I want to obtain the
> letters before the dash. I use the following code. Strangely, when the
> array has a value of "MOD-AS" Label3 displays "3" while Label4
> displays -1.
> What's going on ? What is changing the value of variable mn ? Thanks,
> Jim
> int i = 32;
> string s1;
> string s2;
> s1 = Ante_Arr[i];
> int mn = s1.IndexOf("-");
> Label3.Text = mn.ToString(); // the displayed value is 3
> try
> {
> s2 = s1.Substring(1, mn); // throws an error: length can not be less
> than zero
> }
> catch
> {
> Label4.Text = mn.ToString(); // the displayed value is -1
> }
Substring and ()
Hello,
I have a string which looks as follows: "asdksdjfssdf@dotnet.itags.org.sdfsdfsdfsdfsdf.com (John Smith)"
How to create a substring with only the part which is between (), i.e., the name?
Thanks,
Miguel
you could either use thestring.indexof to find the locations of the parenthesis and then extract the substring..
or you could look at using regex:http://aspnet.4guysfromrolla.com/articles/022603-1.aspx
Consider
PublicFunction GetPersonsName(ByVal ItemTextAsString)AsString
' Sample data - expects constant format as provided, and without
' sure its not really possible anyway.
' "asdksdjfssdf@.sdfsdfsdfsdfsdf.com (John Smith)"
Dim SplitChars()AsChar = {"(",")"}
Return ItemText.Split(SplitChars)(1)' Returns John Smith
EndFunction
rgds,
Martin.
Substring and ()
I have a string which looks as follows:
"asdksdjfssdf@dotnet.itags.org.sdfsdfsdfsdfsdf.com (John Smith)"
How to create a substring with only the part which is between (), i.e.,
the name?
Thanks,
MiguelThere are a couple of ways:
1. Use a Regular Expression
2. Split the string on '(' and remove the ')' from the resulting string
3. Find the position of '(' and ')' with Regex or string search and
substring using these two values to get start and end.
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
****************************************
*********
Think outside of the box!
****************************************
*********
"shapper" <mdmoura@.gmail.com> wrote in message
news:1159644569.490605.218750@.k70g2000cwa.googlegroups.com...
> Hello,
> I have a string which looks as follows:
> "asdksdjfssdf@.sdfsdfsdfsdfsdf.com (John Smith)"
> How to create a substring with only the part which is between (), i.e.,
> the name?
> Thanks,
> Miguel
>
Substring and ()
I have a string which looks as follows:
"asdksdjfssdf@dotnet.itags.org.sdfsdfsdfsdfsdf.com (John Smith)"
How to create a substring with only the part which is between (), i.e.,
the name?
Thanks,
MiguelThere are a couple of ways:
1. Use a Regular Expression
2. Split the string on '(' and remove the ')' from the resulting string
3. Find the position of '(' and ')' with Regex or string search and
substring using these two values to get start and end.
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
*************************************************
Think outside of the box!
*************************************************
"shapper" <mdmoura@.gmail.comwrote in message
news:1159644569.490605.218750@.k70g2000cwa.googlegr oups.com...
Quote:
Originally Posted by
Hello,
>
I have a string which looks as follows:
"asdksdjfssdf@.sdfsdfsdfsdfsdf.com (John Smith)"
>
How to create a substring with only the part which is between (), i.e.,
the name?
>
Thanks,
>
Miguel
>
substring of an array. Weird results!
I've done this many times but this is a first for this problem. I have a string which I do a split on a specific char, the $ sign.
{D}United States,Lettie,C,Letas,52 Alpha Lane,4 Schilling Lane,Test City,District of Columbia,12345-
1234,betabetty@dotnet.itags.org.here.com,101-1010,121-1212,555-555-5555,Bob Beta
{B}5/30/1976,Female,5'4,110,27,118,74,127,42,85
{L}134,bettyB01,bBob1231950,What is your favorite snack?,Gum drops
$
I then want to get specific parts of the string so I do an substring on this only to get the:
Index and length must refer to a location within the string.
Parameter name: length
error message on this bit of code. b = {B} and l = {L} which can been seen in the text above.
int t1 = separateParticipants[0].IndexOf(b);
int t2 = separateParticipants[0].IndexOf(l);
litUploadError.Text = separateParticipants[0].Substring(t1,t2);
A couple things I've tested that worked correctly.
litUploadError.Text = separateParticipants[0].Substring(0,t1);
litUploadError.Text = separateParticipants[0].Substring(0,t2);
int t1 = 0;
int t2 = separateParticipants[0].IndexOf(l);
litUploadError.Text = separateParticipants[0].Substring(t1,t2);
Since they both worked with 0, it should mean that t1 and t2 exist, so why is it that when I try to get the data between t1 and t2, it gives the error?
thanks ^_^
Your problem is that you are requesting too many characters. t2 is the index of {L}, but the number of characters that come after t2 is less than the number that come after it.
To be more clear, the definition of paramters for substring is (start Index, Number Of characters); it doesn't fetch the string between two given indices.
Your last piece of code should be:
litUploadError.Text = separateParticipants[0].Substring(t1, (t2 - t1) +1);
LOL! You are so right. Can't believe I missed that. Guess I need another beer. Thanks a bunch. :)
substrings
i don't know if it is because it's friday, or the last day of my internship, or if i'm just retarted but..I've got string data such as CLIENT/Bob and want to drop the client part. I know i've gotta use substring, but the client part changes so i was wondering if i can use substring in a manner which will allow to me to get everything after the backslash.
first, use the indexOf property to find the position of the slash
Dim myVar as string
Dim pos as Integer
myVar="Client/Bob"
pos=myVar.IndexOf("/")
myVar=myVar.SubString(pos)
this may need a little tweaking - it's all ottomh
string user = "CLIENT/bob";
string usernoclient = user.SubString(user.LastIndexOf("/")+1);
string text = "CLIENT/Bob";
if (text.Length > 0 && text.IndexOf("/") >=0)
{
string client = text.Substring(text.IndexOf("/") + 1, text.Length - (text.IndexOf("/") + 1));
}
Thanks
substring value
i just cant set strat value to have a substring value..i.e...let suppose i have string a="asd,bsd,csd,dsd";
now i want to separate asd,bsd..using substring method.
pzl help me.Split could helps you
For info seString.Split Method
subtracting 2 times in string format
Hi,
I have 2 strings in "HH:mm" format, for example "03:55" or "22:09"
Is there any easy to way subtract 2 strings in this format ??
such that if string1 ="22:10"
and string2 = "01:30"
then answer should be string1 - string2
"20:40"
Thanks,
Split the strings into arrays, then do the math on the arrays.
string[] astrMySTring = DateString.Split(":");
then cast them as integers.
however, you might want to use the Date functions to do date Calculations... base 60 is a pain... crazy Babylonians.
Monday, March 26, 2012
Suggested Microsoft way
naming convention for variables (Am I right?).
Ex: Dim strMyName as String --> Dim str_MyName as String
Any one has any comments. Am I talking some thing does not makes sense. If
you have any URL which tells the Microsoft suggested way on coding standard
please share with me.
Thank you very much.
MarioHaven't heard that. Last I heard, MS was recommending against that
sort of overaggressive hungarian notation in favor of camelCasing and
reliance on Intellisense to remind you of types. They've also dropped
the m_'s for members in favor of a simple underscore:
Dim myName as String
Dim _myPrivateMemberVariable as Int
Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/
"Mario Novado" <MNovado@.hotmail.com> wrote in message
news:O6wpqACpFHA.2580@.TK2MSFTNGP09.phx.gbl...
> Lately I came to know that Microsoft is suggesting to go with underscore
> for
> naming convention for variables (Am I right?).
For readability, an "applicant_last_name" is easier to recognize than an
"ApplicantLastName".
It is also easier for disabled persons to read (Section 508 compliance). I
could be wrong on this part (s-508).
John
I found these interesting links.
Naming conventions from MSDN
http://msdn.microsoft.com/library/d...gguidelines.asp
Designing .NET class libraries: Naming Conventions (they talk about banning
the use of Hungarian notation)
http://msdn.microsoft.com/netframew...ingconventions/
MSDN link about capitalization
http://msdn.microsoft.com/library/d...ationstyles.asp
This one has a chat with Brad Abrams (sp).
http://msdn.microsoft.com/chats/tra...ven_012605.aspx
From what I've read, they are trying to de-emphasize the hungarian notation
for publicly exposed members in favour of Pascal naming (upper case and no
underscores).
Suggested Microsoft way
naming convention for variables (Am I right?).
Ex: Dim strMyName as String --> Dim str_MyName as String
Any one has any comments. Am I talking some thing does not makes sense. If
you have any URL which tells the Microsoft suggested way on coding standard
please share with me.
Thank you very much.
MarioHaven't heard that. Last I heard, MS was recommending against that
sort of overaggressive hungarian notation in favor of camelCasing and
reliance on Intellisense to remind you of types. They've also dropped
the m_'s for members in favor of a simple underscore:
Dim myName as String
Dim _myPrivateMemberVariable as Int
Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/
"Mario Novado" <MNovado@.hotmail.com> wrote in message
news:O6wpqACpFHA.2580@.TK2MSFTNGP09.phx.gbl...
> Lately I came to know that Microsoft is suggesting to go with underscore
> for
> naming convention for variables (Am I right?).
>
For readability, an "applicant_last_name" is easier to recognize than an
"ApplicantLastName".
It is also easier for disabled persons to read (Section 508 compliance). I
could be wrong on this part (s-508).
John
I found these interesting links.
Naming conventions from MSDN
http://msdn.microsoft.com/library/d...gguidelines.asp
Designing .NET class libraries: Naming Conventions (they talk about banning
the use of Hungarian notation)
http://msdn.microsoft.com/netframew...ntion
s/
MSDN link about capitalization
http://msdn.microsoft.com/library/d...ationstyles.asp
This one has a chat with Brad Abrams (sp).
[url]http://msdn.microsoft.com/chats/transcripts/net/design_naming_conven_012605.aspx[/
url]
From what I've read, they are trying to de-emphasize the hungarian notation
for publicly exposed members in favour of Pascal naming (upper case and no
underscores).
Saturday, March 24, 2012
Sum result in Label field
I summed a column of numbers and would like to put them in a Label field to display the result. I understand the conversion for number to string, I don't understand how to that value, that has been summed, to do it.
thanks
grady
int x = 7;
int y = 7;
int z = x + y;
LabelID.Text = z.ToString();
Is that what you're looking for?
HTH,
Ryan
Actually I have summed a column called TFsum and I was trying to display that and it say it was undeclared.
Here is the SQL:
SELECT SUM(filesfailed) AS TFsum
FROM accmonreport
WHERE oa='ddlOA'
HAVING SUM(filesfailed)=0
ddlOA is a dropdown list in the first view on the page. I'm just to get the variable TFsum to do some calculations.
thanks
grady
Could you post the relevent code?
Ryan
All I'm trying now is get the TFsum value into the lblcompliant label.
thanks
grady
Imports System.Data
Imports System.Data.OleDB
Imports System.Data.OleDb.OleDbDataReader
Partial Class reports_508report
Inherits System.Web.UI.Page
Protected Sub SubmitBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If (Page.IsValid) Then
Dim ddlOA As String = ddloalist.SelectedValue
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
"c:\accmon\database\accmon.mdb" & ";"
Dim MySQL As String = "SELECT SUM(filesfailed)AS TFsum FROM accmonreport WHERE oa='ddlOA' HAVING filesfailed=0"
Dim MyConn As New OleDbConnection(strConn)
Dim cmd As New OleDbCommand(MySQL, MyConn)
MyConn.Open()
cmd.ExecuteReader()
MyConn.Close()
lblCompliant.Text = " "
OAReport.SetActiveView(Result)
End If
End Sub
End Class
You need to make a couple of changes.
If (Page.IsValid) Then
Dim ddlOA As String = ddloalist.SelectedValue
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
"c:\accmon\database\accmon.mdb" & ";"
Dim MySQL As String = "SELECT SUM(filesfailed)AS TFsum FROM accmonreport WHERE oa='" & ddlOA & "' HAVING filesfailed=0"
Dim reader As OleDbDataReader
Dim MyConn As New OleDbConnection(strConn)
Dim cmd As New OleDbCommand(MySQL, MyConn)
MyConn.Open()
reader =cmd.ExecuteReader()
While reader.Read()
lblCompliant.Text = reader("TFsum")
End While
reader.Close()
MyConn.Close()
OAReport.SetActiveView(Result)
End If
HTH,
Ryan
Thanks, I really appreciate your time and knowledge. If you don't mind, I have one more question. In Coldfusion there is a function that gives me a recordcount after every query. How do you implement something like that in .Net?
thanks
grady
Thursday, March 22, 2012
supervision on mass e mail sending
Sub Mailshot(ByVal adress As String, ByVal subject As String, ByVal body As String)
Dim msgmail As MailMessage = New MailMessage()SmtpMail.SmtpServer = "smtp.012.net.il"
msgmail.From = "shoresh@dotnet.itags.org.shoresh.org.il"Try
msgmail.To = adress
msgmail.Body = body
msgmail.Subject = subject
msgmail.BodyFormat = MailFormat.Html
SmtpMail.Send(msgmail)
Catch exc As Exception
'DO WHATEVER ERROR HANDLING
End Try
msgmail = Nothing
End Sub
my site have something like 1000 users. and i call the sub one by one (for...next loop)
I have two questions about this e mail sending:
1) does this loop is going to overflow? if yes, what should i do to prevent it?
2) do i have any way to supervise the sending progress, i should to refresh the page every time, something that i think is not so good idea!!
thanksA For...Next loop is better suited for what you are trying to acomplish
i do use a for next loop to call the sending procedure. i wondered if this calling again and again wont stuck it.
Can you create a group and put all your users on it and then just send an email to the group?
Suppress Form Action
Namespace Confirm
Public Class ShowConfirm : Inherits Button
Private strConfirmMsg As String
Public Property ConfirmMessage() As String
Get
ConfirmMessage = strConfirmMsg
End Get
Set(ByVal value As String)
strConfirmMsg = value
End Set
End Property
Protected Overrides Sub AddAttributesToRender(ByVal Output As HtmlTextWriter)
MyBase.AddAttributesToRender(Output)
Output.AddAttribute(HtmlTextWriterAttribute.OnClick, "ConfirmMsg()")
End Sub
Protected Overrides Sub RenderContents(ByVal Output As HtmlTextWriter)
Output.Write(vbCrLf)
Output.Write("<script language='JavaScript'>")
Output.Write(vbCrLf)
Output.Write("function ConfirmMsg(){")
Output.Write(vbCrLf)
Output.Write("var answer = confirm('")
Output.Write(strConfirmMsg)
Output.Write("')")
Output.Write(vbCrLf)
Output.Write("location.href = window.location.href + '?Proceed=' + answer")
Output.Write(vbCrLf)
Output.Write("}")
Output.Write(vbCrLf)
Output.Write("</script>")
End Sub
End Class
End Namespace
Using VBC, I compiled the above intoConfirm.dll. This is how I am using the above custom control in an ASPX page (assume that the ASPX page is namedConfirm.aspx):
<%@dotnet.itags.org. Register Assembly="Confirm" Namespace="Confirm" TagPrefix="CC" %
<form EnableViewState="true" runat="server">
<CC:ShowConfirm ID="ShowConfirm1" ConfirmMessage="WANNA EXIT?" Text="EXIT" runat="server"/>
</form>
Note the
Output.Write("location.href = window.location.href + '?Proceed=' + answer")
line (which is highlighted) in the VB class file code. When the ASPX page gets rendered, it displays a Button. Conventionally, when a Button is clicked in an ASPX page, it posts back to itself using the POST method. When the Button in the above custom control is clicked, a JavaScriptconfirm dialog pops-up with 2 buttons -OK &Cancel. IfOK is clicked, the value of the JavaScript variableanswer istrue & ifCancel is clicked, the value of the variableanswer isfalse.
What I want is irrespective of whether a user clicks theOK orCancel button in theconfirm dialog, instead of posting back to itself using the conventional POST method, I want the ASPX page to post to itself BUT with a querystringProceed=<value> appended i.e. I want to suppress the conventional post & instead add the querystring so that I can find out whether the user has clicked theOK button or theCancel button in theconfirm dialog. If the user clicksOK, he will be taken to
http://myserver/aspx/Confirm.aspx?Proceed=true
On the other hand, if the user clicksCancel in theconfirm dialog, he will be taken to
http://myserver/aspx/Confirm.aspx?Proceed=false
Can this be done in anyway?
Output.AddAttribute(HtmlTextWriterAttribute.OnClick, "ConfirmMsg();return false;")
Thanks, mate, your suggestion turned out to be a great one. Could you please tell me what role doesreturn=false; which you have appended afterConfirmMsg(), play here?
Going by your suggestion does add the querystringProceed=<value> at the end of the URL but there's a *** here. Suppose when a user clicks the server-side Button; he is shown the JavaScriptconfirm dialog with theOK &Cancel buttons. If the user clicksOK, then he is taken to
http://myserver/aspx/Confirm.aspx?Proceed=true
That's fine but if the user clicks the server-side Button once again & clicksCancel in theconfirm dialog, then he is taken to
http://myserver/aspx/Confirm.aspx?Proceed=true?Proceed=false
i.e. the querystring gets appended twice. In other words, a querystringProceed=<value> will go on getting appended at the URL wheneverOK &Cancel is clicked in the JavaScriptconfirm dialog. For e.g. if a user clicks eitherOK orCancel in theconfirm dialog 5 times, then the querystring will get appended one after the other 5 times.
Any workaround to overcome this?
Tuesday, March 13, 2012
switch connection string in xsd file
Hi,
I have 2 connectionstrings in the web.config file in my website. It has a xsd file of handling all the database calls etc.
I wonder how do I switch the connectionstring used in the xsd file in code-behind?
Basically, my web.config will have a setting indicates whether website is test mode or live mode in appSetting region:
<add key="mode" value="">
So:
<add key="mode" value="test"> <!--is testing mode-->
<add key="mode" value="live"> <!--is live mode-->
depend on this than the whole site is using the appropriate connection string, sample code:
public static string ConnectionString
{
get
{
if (IsTesting)
{
return ConfigurationManager.ConnectionStrings["Test"].ToString();
}
else
{
return ConfigurationManager.ConnectionStrings["Live"].ToString();
}
}
}
But how to you set the xsd file following this rule?
Thanks in advance.
Hi,
As far as I can see, we don't use .xsd file to switch this. From your code, I can see that your ConfigurationManager is reading from web.config for the targeted connectionstring directly. So the only thing we need to do is to set the IsTesting flag. I think you can add a new key in Web.Config to indicate if the testing mode is true or false.