|
hi,
I am creating one web applications but the sql database file is not added.
Add New item---> Sql database file -->database.mdf--->OK
It shows the following error message:
"Object reference not set to an instance of an object"
I am trying to add that file in "app_data" folder.But the same error message shown.Is there any .net installation problem????
|
|
|
|
|
Hi
I want to extract sustrings from a string and want to store in an array.
The string is dynamic it will change but the criteria to extract substring is same.
say for example a string str="something is [!better] than [!nothing]"
so i need to extract [!better] and [!nothing] from the string and store it in a string array, the string is dynamic it changes but i need to extract data between [ and ] including both the square brackets.
If anybody can send any sample code, I will be very thankfull.
Thanks
Ansari
|
|
|
|
|
|
string.Split method.
string str = "something is [!better] than [!nothing]";
string[] separators = new string[] { "[!better]", "[!nothing]" };
string[] strArray = str.Split(separators, StringSplitOptions.RemoveEmptyEntries);
foreach (string item in strArray)
{
Console.WriteLine(item.Trim());
}
Edit: Just reread the question and you want the exact opposite!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
It would probably end up being a three-step process. If it's safe to assume that the stuff you're looking for would always be separated by a space, you could do this:
string str = "something is [!better] than [!nothing]";
string[] parts = str.Split(' ');
List<string> resultStringList = new List<string>();
foreach (string part in parts)
{
int pos1 = part.IndexOf("[");
int pos2 = part.IndexOf("]");
if (pos1 >= 0 && pos2 >= 0)
{
string result = part.SubString(pos1+1, pos2);
resultStringList.Add(result);
}
}
string[] myResults = new string[resultStringList.Count];
for (int i = 0; i < resultStringList.Count; i++)
{
myResults[i] = resultStringList[i];
}
</string></string>
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
modified on Tuesday, September 16, 2008 10:23 AM
|
|
|
|
|
Hi John
I have a string which do not have spaces. Its something like this "<p>[!vDescription][!vDate]</p><p>[!vTitle]</p>", Sorry to not mention it in my earlier post. Hope you will reply back with the solution. Thanks for your reply.
Thanks
Ansari
|
|
|
|
|
|
How about a one-liner to extract the strings from the array using a regular expression and placing them in an array?
string[] substrings = Regex.Matches(str, @"\[.*?\]").OfType<match>().Select(m => m.Value).ToArray();
Despite everything, the person most likely to be fooling you next is yourself.
modified on Tuesday, September 16, 2008 12:18 PM
|
|
|
|
|
Hi Guffa
Thanks for your reply.
I am getting "Invalid expression term '>'" error. Please help resolve this issue.
Thanks
Ansari
|
|
|
|
|
Hi
After doing r&d on regular expressions I got this answer.
If we want to extract a word from a string like "[something]" We could use the Match method in the regular expression.
Like this:
string s = "<p>[!vDescription][!vDate]</p><p>[!vTitle]</p>";
Regex rx = new Regex(@"\[.*?\]");
Match mc = rx.Match(s);
while(mc.Success)
{
Response.Write(mc.Value.ToString());
mc = mc.NextMatch();
}
Thanks
|
|
|
|
|
Use the Matches method to get them all:
MatchCollection matches = Regex.Matches(s, "\[.*?\]");
string substrings[] = new string[Matches.Count];
for (int i = 0; i < matches.Count; i++) {
substrings[i] = matches[i].Value;
}
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi Guffa
My requirement changed, I am sure you can help me.
I have a string for example str="something [!str1] and something [!str2].."
so I want to store the substring from start up till "[" and then from "[" to "]" and so on.
so how can we achieve it.
Thanks
Ansari
|
|
|
|
|
Split on brackets, then you get an array containing the strings between the brackets.
string str="something [!str1] and something [!str2] else.";<br />
string[] substrings = str.Split(new char[]{ '[', ']' });
This gives you an array with the following strings:
"something "<br />
"!str1"<br />
" and something "<br />
"!str2"<br />
" else."
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks a lot Guffa for your quick reply.
It works great.
modified on Friday, September 19, 2008 5:54 AM
|
|
|
|
|
You are probably not using framework 3.5 - Linq
|
|
|
|
|
hi all,
how do we can add rows into datatable from Dataset or bindingsource or tableadater ?
|
|
|
|
|
what exactly are you trying to do?
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
i just want load data from sql server
|
|
|
|
|
zeeShan anSari wrote: i just want load data from sql server
into what?
And if you just want to query a db and bind the result to a DataGridView for example there is no reason to manually add rows to a DataTable.
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
after loadin data into datatable then i would manipulate the data and also use datatable for searching purpose.......
|
|
|
|
|
after loading data into datatable then i would manipulate the data and also use datatable for searching purpose.......
|
|
|
|
|
for data manipulation have a look at the SqlDataAdapter class, also read up on the disconnected layer of ADO.Net.
Searching you can do with the DataView class.
I dont have time to give you code examples right now, if you have troubles ill give you some in a few hours.
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
yes i need your help...but that time u r so busy, so i can wait for few hours
|
|
|
|
|
Im developing in C# and im changing the selected index of a combox box dynamically during coding, and on selectedindex event i want to load another combobox. My problem is the second combobox is not being loaded when the first one's changed during runtime, its only trigering the selectedindex changed when i do a click, does nayone know whats missing from my code.
Please Note that i had posted this question on ASP forum but was adviced to use this forum.
Thank you.
|
|
|
|
|
Did you set your combo box autopostback property to true? If not try it. Your problem will probably be solved.
|
|
|
|