|
Hi everybody,
I want to find in html string specific attributes and remove everything in between.
EX:
<>
<>
<>
<>
<>
<>
<>
<>
I want to remove all and in between
Thank you
|
|
|
|
|
|
I'm using VB.net 2013 , Entity framework and SQL Server 2008R2.
I have a strange situation: I have a form/wizard that restores a database from a copy. I restore the database using SMO.The restore is completed without problems, but immediately after restore I try to connect to database using this code :
Dim context as MyEntity
context=New Myentity
query = From t in context.Mytable select t
I get an error :
An exception has been raised that is likely due to a transient failure. If you are connecting to a SQL Azure database consider using SqlAzureExecutionStrategy.
If a try after some time the same code , everything is ok.
What can I do ?
Thank you !
|
|
|
|
|
dilkonika wrote: What can I do ? Retry[^] the operation. The fact that the database has been restored completely doesn't mean it is immediatly available for querying. Give the server a second to attach and load, and try to connect again.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Sorry ! But the sql server is on local PC , and on the computer where I have created the application (inside Visual studio , or with the final exe ) everything is ok. Only on the computer where I try to install and run my application I have this error.
|
|
|
|
|
dilkonika wrote:
Sorry ! But the sql server is on local PC , and
on the computer where I have created the application (inside Visual studio , or
with the final exe ) everything is ok. Only on the computer where I try to
install and run my application I have this error.
No sorry's required; I don't consider it an error, as it is likely that the server is still loading the database. Is the database-server that gives the error also hosting other databases? Than that might explain why it takes longer there than on your machine.
The most likely difference is the production machine's database is probably set to "simply recovery mode".
You might also want to be checking the event-log; see if SQL Server has dropped any hints there. You might also want to try the backup/restore procedure with another database, like the AdventureWorks database from Microsoft. If that also takes long, then it is due to something in that machine; be it different hardware, different software or different settings.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Dim i As Integer
Dim s As String = "Aaa"
Dim pAR() As String = Split("aaa,AAA,bbb,BbB,ccc,CcC", ",")
i = Array.FindIndex(pAR, Function(x) x.IndexOf(s, StringComparison.InvariantCultureIgnoreCase))
Returns 2 but I would expect it to be 0.
|
|
|
|
|
It says 2 because you're asking the FindIndex function to return the first element where the x.IndexOf call returns a non-zero value, and that's at index = 2.
In most languages, a non-zero value is always considered True and a zero value is False.
Read up on the IndexOf() and String.Compare() documentation and you'll understand why it's not behaving like you think it should.
To get it to work like you want, you'd change that line of code to:
i = Array.FindIndex(pAR, Function(x) x.IndexOf(s, StringComparison.InvariantCultureIgnoreCase) = 0)
|
|
|
|
|
Thanks
I am very familiar with IndexOf. I was looking for a case insensitive version of IndexOf when I came across this code.
The MSDN doc for FindIndex has
returns the zero-based index of the first occurrence within the List(Of T) or a portion of it.
So I was expecting it to return 0 since the first occurrence of a case insensitive "Aaa" in
"aaa,AAA,bbb,BbB,ccc,CcC"
would be 0 not 2. (2 would be bbb)
I do want to index in the entry in the array not a True or False.
Now you code DOES WORK so thanks but I do not see how it matches the MSDN doc and why your code works.
|
|
|
|
|
Remember, I keep emphasizing that a non-zero value evaluates to True and a zero value is False.
You're not actually understanding how the FindIndex and IndexOf methods work. FindIndex will return the first item passed to the comparator function you provide that returns True (a non-zero value).
Keeping that in mind, IndexOf returns an integer value of the index in the string where the string you're searching for is found. Zero if the term to search for is Empty(False), a value of 0 or greater if it is found (True) and -1 if it is NOT found (True!).
So, rewrite your code to break things out a bit more and step through the code in the debugger. Launch it by hitting F11, not F5, and step through the code one line at a time by hitting F11 and then hover the mouse over the variables you want to inspect the values of.
Sub Main()
Dim i As Integer
Dim s As String = "Aaa"
Dim ar() As String = Split("aaa,AAA,bbb,BbB,ccc,CcC", ",")
i = Array.FindIndex(ar, Function(x) Contains(x, s))
Console.WriteLine("I is " & i)
End Sub
Private Function Contains(a As String, b As String) As Integer
Dim returnValue As Integer = a.IndexOf(b, StringComparison.CurrentCultureIgnoreCase)
Console.WriteLine("Searching for '{0}' in '{1}' returning: {2}", b, a, returnValue)
Return returnValue
End Function
To fix this version, it's that same as before:
Sub Main()
Dim i As Integer
Dim s As String = "Aaa"
Dim ar() As String = Split("aaa,AAA,bbb,BbB,ccc,CcC", ",")
i = Array.FindIndex(ar, Function(x) Contains(x, s) = 0)
Console.WriteLine("I is " & i)
End Sub
Private Function Contains(a As String, b As String) As Integer
Dim returnValue As Integer = a.IndexOf(b, StringComparison.CurrentCultureIgnoreCase)
Console.WriteLine("Searching for '{0}' in '{1}' returning: {2}", b, a, returnValue)
Return returnValue
End Function
modified 23-Jun-14 17:16pm.
|
|
|
|
|
Dave Kreskowiak wrote: Zero if it's not found (False), a value greater than 0 if it is found (True) and -1 if it is NOT found (True!).
In other words, "if it's not found it returns 0, but if it's not found it returns -1".
Well, that's not going to confuse matters at all!
If the sub-string is not found, it returns -1; if it is found, it returns the zero-based index at which it was found. It the sub-string is found at the start of the string, it returns zero.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Crap.
Mistyped that one! It should be if the string to search for is Empty, 0 is returned.
|
|
|
|
|
You've still got "a value greater than 0 if it is found", which should be "greater than or equal to 0" - if the sub-string is found at the start of the main string, IndexOf will return 0 .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Grrr....fixed!
I picked the wrong week to stop sniffing glue!
|
|
|
|
|
Is there a TimeZoneInfo in VB.NET 2005, all I can use is TimeZone.
that does't mean that I can't do it
|
|
|
|
|
The TimeZoneInfo class was added in .NET 3.5, so you'll need Visual Studio 2008 or higher.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello,
I am trying to get my program to open an external program. I also plan to make this portable, so I made a folder for my program to go to.
It's like this: Click OpenOffice and my program manager will go to:
Vegrard Suite\Vergard\OpenOffice\program\soffice.exe
This folder is located in the root directory of the program; wherever this root directory is in will make the program read the folder that's in its root directory.
The problem, however, is that I can't get the program to launch without going to a fixed location on the C drive "C:\Users\User\My Documents\Visual Studio 2010\Projects\Vergard Suite\Vergard\OpenOffice\program\soffice.exe". The idea is that wherever you put the application folder (Vergard Suite) , the program will always refer to the folder that the application is in to open the program (Vergard Suite\Vergard\); therefore, it can be made portable (like Windows 3.11: wherever the WINDOWS directory is located, Windows will go to the program's folder that was specified).
How do I get this to work???
Marquis Kurt
---------------------------
Parament Technologies
|
|
|
|
|
Your question doesn't make a lot of sense. It may be obvious to you but the description is missing some critical detail.
Why would OpenOffice be under your Projects folder?
There are two paths to be aware of when launching an application. The first is the fully qualified path to the executable you're trying to launch. What this path contains is entirely dependent on when the application is installed. How are you getting this path?
The second is the "Startup Directory". This is what the current path should be when the target application is launched. Normally, this path doesn't matter at all, but some apps do require it. How are you going to determine if the app requires this and how are you going to determine what this path is?
There are the "well-known" paths that Windows supplies. Using the Environment.GetFolderPath() method will return the path of certain folders using an enumeration value to determine which folder you want the path for. See the documentation for GetFolderPath()[^] and SpecialFolder enumeration[^] for more information.
|
|
|
|
|
This is what I mean:
Say you want to launch a program called "Banana" through the program manager. The program manager is located on your desktop. The program manager will check inside its folders, not the entire C: drive for that particular PC, for this program, and finds it at:
\Vergard\Banana\Banana.exe
The program will then launch Banana.exe from \Vergard\Banana\Banana.exe, not C:\Users\Me\Desktop\Vergard Suite\Vergard\Banana\Banana.exe.
Now say that you copy Vergard Suite to your flash drive. You go to your friend's computer and try to launch your program through the program manager. What's supposed to happen is Vergard will go to \Vergard\Banana\Banana.exe, not C:\Users\Me\Desktop\Vergard Suite\Vergard\Banana\Banana.exe. This can be proven effective if it works. It's like that command in batch scripts: ".\Vergard\Banana\Banana.exe".
How can I get it so that my program mananger will execute a command similar to the bstch command to open that file, no matter where the program manager's files are?
Oh, about the OpenOffice: I put it in the Projects folder to test the program manager's ability to OpenOffice.
|
|
|
|
|
You still have to build a complete path to the .EXE, not a relative one. This is because the relative path would be relative to whatever the "current directory" is and that can change without your code knowing it.
Since the folder is under your program files folder, you can get the path to your own .EXE by using Application.StartupPath. You can then build the remaining path to the target .EXE using the methods in the Path class[^].
|
|
|
|
|
I just realized this... Is it possible to have my application run that bstch script command? I know people have made CMD redirects before, so theoretically, it should work, right?
|
|
|
|
|
What "bstch" command? There's no such thing in Windows and any script lanugage I know of.
|
|
|
|
|
Oops... I meant batch script.
http://commandwindows.com/batch.htm
|
|
|
|
|
Yes, you can run a batch script using the Process class.
|
|
|
|
|
Open a command window. Type "Path".
Those are the folders that Windows searches if you do not specify a location. If it ain't in there, it won't be found, unless you specify a full path.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|