|
I'm trying to compare words entered in a textbox with a selection of stop-words, removing any stopwords that are found. Here's a snippet.
string text = this.textBox1.Text;
if(RemoveMe(s))
{
int startIndex = text.IndexOf(s);
int endIndex = s.Length-1;
text = text.Remove(startIndex, startIndex+endIndex);
}
Problem is, every now and then startIndex get a value of -1...
Kinda stumped here, what am I doing wrong?
|
|
|
|
|
When the iterator reaches the end it sets itself at -1. You need to re-set it at 0 after each string that you are finished with
|
|
|
|
|
int startIndex = text.IndexOf(s);<br />
int endIndex = s.Length-1;<br />
text = text.Remove(startIndex, s.Length);
works fine for me.
Remember the second parameter to "Remove" number of chars to delete, not the endIndex
Can you give us some example strings you are trying to find in "text"?
modified 12-Sep-18 21:01pm.
|
|
|
|
|
hehe...thanks, would have had to be something that simple...
I'm removing common words such as 'at' 'the' 'this' 'is' 'of' etc...
|
|
|
|
|
The IndexOf method returns -1 when the string is not found. You have to check if the word is even present in the string before you try to remove it.
Also, your method is only removing the first occurance of the word. Why don't you use a Replace instead? Or why not use a regular expression? Then you can match the word boundaries, so that you don't accidentally remove a part of a word that matches another word.
---
b { font-weight: normal; }
|
|
|
|
|
I'd use regex but they always leaves me scratching my head somewhat puzzled
Thanks for the suggestions, off to try it in the code now
|
|
|
|
|
They're simple, really
Just take yourself a week and learn it, it's worth a lot when dealing with strings.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
yeah, I've kinda put it off long enough
thanks
|
|
|
|
|
Hi there. I'm creating an installer file for the program that I have completed. I want the installer to install the program into the correct folder, etc.
Question:
Does anybody know how to use the tools in Visual Studio to make my "installer.exe" file add a shortcut to the StartUp folder of windows, so that the installed program would run every time a user logs into windows?
Any other alternatives?
thanks.
|
|
|
|
|
|
hi Marazm,
I have having the same problem. I have deveoped a code and wanna create the installer for that. Would you please let me know how to do it?
Regards,
Amit
|
|
|
|
|
Here are the steps:
1) create new project, of type "Setup and Deployment Projects", then on the right select "setup project".
2) right click on the name of the project in the solution explorer and "add" your .exe file and your icon files.
...then...
3)you will see
file System on Target Machine
Application Folder //how your files are installed
User's Desktop //files added to user's desktop
User's Programs Menu //files added to user's start-menu
4)Go to the Application Folder. Right click into the empty space, and add your .exe file. Set up using right-clicks, such as setting the icon. Also set up the default installation path by right clicking on the folder.
5)Right-click on the .exe file and choose "create shortcut". Place that in "User's Desktop" if you want a shortcut to the file to appear. Choose the icon as well for the shortcut.
6)Inside "User's Program Menu", create a folder, call it "Startup". Inside of it create a shortcut, as was described above in 4. This will put your program's shortcut into STARTUP by default
...finally...
build your project and you're all set.
|
|
|
|
|
|
I have a question. I created a NavyBatlle with sockets that the client or server sends the coordinates to hit the opponent, drawing and "X" ou a "O".
My problem is:
In the first time the data is send for the server, the figure is drawn, on the second, appears the following runtime error: "Invalid parameter used". Wasn't the error appears since the beginning?
Thanks a lot for who helps me.
Below the problematic server's piece:
Ah, I've implemented the IDsposable interface in my Draw class:
private void DrawX(int iX, int iY, Graphics G)
{
using(G)
{
Pen pColor = new Pen(Color.Blue);
pColor.Width = 5;
Point pA = new Point(iX, iY);
Point pB = new Point(iX+30, iY+30);
Point pA1 = new Point(iX+30, iY);
Point pB1 = new Point(iX, iY+30);
G.DrawLine(pColor,pA,pB);
//Nessa parte é que dá problema
G.DrawLine(pColor,pA1,pB1);
}
}
The part that I created the class and call the method to get the coordinates:
do
{
sData = Reader.ReadString();
using(Draw Desenho = new Draw())
{
Desenho.GetCoordinates(sData, G);
}
}while(DataStream != null && sData != "Close connection");
On client I just call the Write method of my BinayWriter to(of course) send data on the stream.
One more time thanks a lot.
|
|
|
|
|
I wonder if you need to refresh your connection after sending the first value stream. Or possibly re-set the object you are sending out. I have had problems before trying to re-send the same object that eventually gets corrupted. Hmmm, sorry no concrete answers but I suppose some possibilties to look at.
|
|
|
|
|
No, my connections are in threads. Talking about my object, I'm using the "using" keyword. I commented this part to see if was it that cause my problem but no.
Man, I'don't know what I do. Am I answered your doubt?
Thanks for help one more time
|
|
|
|
|
Before I pull out my hair out, throw the computer out the window, step on the neighbours cat, drive my car over the cliff or all of the above......I thought maybe I could ask for some help.
The concept is simple....or so it would seem.
I want to call a WebMethod with my credentials and get the information about my account back. Hmmm, should be a piece of cake. The problem is that the class created by wsdl.exe is an abstract class with abstract methods. So I created a class that implements those methods using override.
Here is the basic setup:
The abstract class created by wsdl
<br />
[System.Web.Services.WebServiceBindingAttribute(Name="AccountsSoap", Namespace="http://address")]<br />
<br />
public abstract class ServiceAccounts : System.Web.Services.WebService <br />
{<br />
<br />
[System.Web.Services.WebMethodAttribute()]<br />
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://address/QueryProfile", RequestNamespace="http://address", ResponseNamespace="http://address", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]<br />
<br />
public abstract AccountProfile QueryProfile(Credentials credentials);<br />
<br />
}<br />
The class to implement
<br />
[WebService(Name="ServiceAccounts",Description="Provides a callback mechanism",Namespace="http://address/accounts")]<br />
<br />
public class AccountsImpl : Project.App.Tls.Accounts.ServiceAccounts<br />
{<br />
<br />
[WebMethod(MessageName="QueryProfile",Description="Gets the profile of the specified client.",EnableSession=false)]<br />
<br />
public override AccountProfile QueryProfile(Credentials credentials)<br />
{<br />
}<br />
And finally the call
<br />
private void sendButton_Click(object sender, System.EventArgs e)<br />
{<br />
CredentialCache myCache = new CredentialCache();<br />
<br />
NetworkCredential netCred = new NetworkCredential("name1", "pwd1", "domain");<br />
((CredentialCache) myCache).Add(destUri, "NTLM", netCred);<br />
((CredentialCache) myCache).Add(destUri, "negotiate", netCred);<br />
((CredentialCache) myCache).Add(destUri, "digest", netCred);<br />
<br />
accounts.credentials.Account = "name2";<br />
accounts.credentials.Password = "pwd2";<br />
<br />
accountProfile = accounts.QueryProfile(accounts.credentials);<br />
}<br />
Now, I'm sure you are all wondering what my problem is....My problem is that I don't know what to put in my implementation of QueryProfile() to make it call the webMethod. All of the implementations I have seen say to create a new object of ServiceAccounts and then just call the respective method. This code I would put in my QueryProfile() implementation. But since both the ServiceAccounts and the ServiceAccounts.QueryProfile() are both abstract, I cannot create a reference to them.
I know the answer is going to be simple but I cannot figure this out!!!!!!!!
Any input would be appreciative as I kinda like my hair, my computer, the neighbour's cat and especially my car.
Thanks
SnowBlind37 who is CodeBlind37 at this moment
|
|
|
|
|
Hmmm...off the top of my head
try openning the ServiceAccounts class and removing the WebService base class as well as the attributes and the public and abstract modifiers from the methods the get an interface and using it that way?
|
|
|
|
|
I would love to modify the class to make it easier for me. The point is that this is the way it is and will be for other people that access this service(others have been able to do this successfully). My job is to find a way to do this easily and document the procedure. There has to be a way.
Definately CodeBlind37
|
|
|
|
|
|
I already am creating the AccountsImpl instance. But the AccountImpl.QueryProfile() still needs to return a value that will come from the webMethod QueryProfile(). This is a main part of the complication.
|
|
|
|
|
You guys are not going to believe this! When I ran my wsdl.exe I used the server option when I really wanted the client version. It all makes sense now.
I had been trying to look from the other side of an abstract class and could not find a way to make it work. And for good reason because an abstract class is designed to give you ways to implement methods with the same name but with different logic......Not to implement a method to use an abstract method to use varying implementations of a method
Talk about a trip outside the box. I will learn from now on to always take a walk around the box before I bang my head on the inside.
Feeling slightly less CodeBlind today.
Happy Coding All!!!!
|
|
|
|
|
I'm no expert in writing WebServices, but isn't AccountsImpl supposed to be the actual implementation of the QueryProfile web method? This is the code that's supposed to do work of querying the profile and returning an instance of AccountProfile, so how does calling it again solve the problem?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
You are right Senthil! It is the actual implementation of the WebMethod. This is where I got stumped. It turned out that when I ran my wsdl.exe I specified "server". This gave me the server implementaion of the class which was an abstract class.
So on the server side there is an AccountsImpl that implements the abstract method QueryProfile(). This is the class that would do all the work for my call to QueryProfile().
But on the client side all I wanted/needed to do was create a ServiceAccounts object. So when I ran the wsdl.exe without specifying "server" (default is "client") I was given a ServiceAccounts class that was not abstract.
The problem then was that I had obtained (through wsdl.exe) the server implementation when I really needed the client implementation.
A valuable lesson was learned......and the best part is I still have some hair left, I didn't throw my computer out the window, I petted the neighbour's cat instead of stomping on it and my car is still in the driveway.
Regards,
Reserving CodeBlind For The Future..............
|
|
|
|
|
Hi folks!
I need to display video played by an external device (VCR, DVD player) in a .NET application. No need to record it, just generate a preview. How can it be done?
Thanks a bundle!
|
|
|
|