webclient does not recognize the text of the page C# [closed] - c#

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
I have a problem with the web client does not recognize the contents of the web.
public Form1()
{
InitializeComponent();
WebClient webClient = new WebClient();
try
{
if (!webClient.DownloadString("https://pastebin.com/raw/SUVh3TP1").Contains("dasda"))
{
MessageBox.Show("Working!");
}
}
catch
{
}
}

The webClient is successfully downloading that URL and reading the string that's there ("dasda"). Because you have a ! at the start of your if condition, when the .Contains() evaluates to true, the expression in the if evaluates to false and the MessageBox.Show() is skipped.

Related

What is the problem with char equal to ","? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last month.
Improve this question
string odp = "2,1";
bool abs = odp[1].Equals(",");
When I do Console.Writeline(odp[i]) it shows "," symbol so why does it equal to false?
I tried using == instead but it doesn't work either. Thanks in advance
A Char is encapsulated in single quotation marks ',' in C# (a String uses double quotation marks ",").
Try the below instead:
string odp = "2,1";
bool abs = odp[1].Equals(','); // true

c# Registry can't open Subkey with {} [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 11 months ago.
Improve this question
Here is my code
RegistryKey = regsohr;
regsohr = Registry.LocalMachine.OpenSubKey(#"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks\{DFDC1B83-7FD3-4C77-8CD1-7391D1680ACA}");
sw.WriteLine(regsohr.GetValue("Path"));
It can't get into {DFDC1B83-7FD3-4C77-8CD1-7391D1680ACA}.
But when I delete that line everything works fine.
Anyone has any ideas why it can't open this SubKey?
I will appreciate any help.
My bad.
I have messed up with "HKEY_LOCAL_MACHINE".
regsohr = Registry.LocalMachine.OpenSubKey(#"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks\{DFDC1B83-7FD3-4C77-8CD1-7391D1680ACA}");
Fixed it
regsohr = Registry.LocalMachine.OpenSubKey(#"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks\{DFDC1B83-7FD3-4C77-8CD1-7391D1680ACA}");
Try this , for example i put it in a Label to check if it works
{
string readValue;
readValue = My.Computer.Registry.GetValue
(#"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache", "Tasks",Nothing);
Label6.Text = readValue;
}

how to solve the bool function that return one value in C# [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I have the following function:
public bool CheckConn()
{
try
{
if (JvarConn.State == ConnectionState.Closed)
{
JvarConn.Open();
return true;
}
}
catch
{
return false;
MessageBox.Show("No Connection");
}
}
but there is a red line error under the function name and the error is:
not all code paths return value
I tried to not putting a false value but the same error!. how can I solve that problem?
You can add return true;, just before the method closing bracket }. It’s giving error because what if it doesn’t meet the if.
Im returning true based on your method name declaration and implementation inside.

ReplaceTest(int i) not all code paths return a value [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
public string ReplaceTest(int i)
{
string rep = this.textBox3.Text;
string reped = rep.Replace("sir, this.textBox3.Text");
}
Like this? this is what i want to do but another error comes up not all code paths return a value
string.Replace() takes two arguments:
the string to replace
the string to use instead
If you want to remove "sir", it means to replace it with an empty string:
string reped = rep.Replace("sir", string.Empty);

Double quotes in String.Concat [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I want to write
Label "BuildingData" does not exist.
I know how to write using String.format and stringbuilder. I want to write this using String.Concat.
When I write code
String.Concat("Label ","\"","BuildingData","\"", "does not exist.")
The output is
Label \"BuildingData\" does not exist.
Add a space before does and you'll get the correct output. The quotes are a red herring - you're looking in the debugger.
using System;
public class Test
{
public static void Main()
{
var concat = String.Concat("Label ","\"","BuildingData","\"", " does not exist.");
Console.WriteLine(concat);
}
}
Here's the output.

Categories