Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
hi i want to get just the Crm and the number in the line
tenx
string emailsubject = "Email Test 2 CRM:0276002";
public string GetCrmSubjectNum()
{
string final = //;
return "";
}
It is a little bit unclear what you want.
If you always have "CRM" in the subject, then you could do it like following:
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string emailsubject = "Email Test 2 CRM:0276002";
emailsubject = GetCrmSubjectNum(emailsubject);
Console.WriteLine(emailsubject);
Console.Read();
}
public static string GetCrmSubjectNum(string emailsubject)
{
emailsubject = emailsubject.Remove(0, emailsubject.IndexOf("CRM"));
return emailsubject;
}
}
}
I would go with this, because Substring() is the fastest way:
public string GetCrmSubjectNum(string emailSubject)
{
return emailSubject.Substring(emailSubject.IndexOf("CRM:", StringComparison.Ordinal) + "CRM:".Length);
}
Related
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 2 years ago.
Improve this question
Good morning,
I am doing a page for my intership and I found this function but it isn't working, can someone help?
Thank you in advance.
string _id = this.txtIdGrupo.Text;
if (!Regex.IsMatch(_id, #"^\d+$"))
return false;
The output says this:
error CS0103: The name 'Regex' does not exist in the current context
this is not an issue with the bit of code you showed.
This is a namespace issue at the very top of your file.
The solution should be https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/namespaces/
using System;
using System.Text.RegularExpressions;
public class Test
{
public static void Main ()
{
var isNumeric1 = IsNumeric("1");
Console.WriteLine(isNumeric1);
var isNumeric2 = IsNumeric("HelloWorld");
Console.WriteLine(isNumeric2);
//call IsNumeric with the value of this.txtIdGrupo.Text like this
//var isNumeric = IsNumeric(this.txtIdGrupo.Text);
}
private static bool IsNumeric(string str)
{
string id = str;
if (!Regex.IsMatch(id, #"^\d+$"))
return false;
return true;
}
}
See it in action:
https://dotnetfiddle.net/I7cAKs
notice the "using System.Text.RegularExpressions"
Using tools like Resharper and similar will definitely give you hints and will improve your day to day !
Make sure you have the System.Text.RegularExpressions
is imported
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 2 years ago.
Improve this question
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CLASSES_2
{
class Building
{
public int Area; // total square footage of building
public int Floors; // number of floors
public int Occupants; // number of occupants
}
class Building_Demo
{
static void main(string[] args)
{
Building house = new Building();
int Area_Per_Person;
house.Area = 4000;
house.Floors = 7;
house.Occupants = 10;
Area_Per_Person = house.Area / house.Occupants;
Console.WriteLine("The house has: \n" + house.Floors + " Floors \n" + house.Occupants + " Occupants"
+ house.Area + "Area \n" + Area_Per_Person + " Area_Per_Person: ");
}
}
}
Can Someone tell me what's wrong with my code? It's telling me that there is no Method suitable for an entry point.
CS5001 Program does not contain a static 'Main' method suitable for an entry point.
Method names are case sensitive. The method should be called Main, with a capital M, not main like you currently have:
static void Main(string[] args)
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 4 years ago.
Improve this question
I'm trying to make a proof-of-concept command-line software for my team, however something isn't right about my code. The compiler is treating the code as if I'm trying to implicitly convert a string to a bool value, yet I'm not using any booleans here at all, and I by no means am trying to convert anything into one. The following snippet can be used to reproduce the issue:
namespace default {
class test {
static void Main() {
Console.Clear();
string IsDemoMode;
Console.WriteLine("Activate Demo Mode? (Y/N)");
IsDemoMode = Console.ReadLine();
if (string IsDemoMode = "Y")
{
// Demo code...
} else
{
// Non-Demo Code...
};
}
}
}
The question here is: Why is Visual Studio thinking I'm trying to convert a string to a boolean when I'm not even close to doing that? Does the compiler expect a boolean to be there instead of a string?
You are using = instead of ==. So string = "some text" will give you string. And string == "some text" will give you bool
namespace default {
class test {
static void Main() {
Console.Clear();
string IsDemoMode;
Console.WriteLine("Activate Demo Mode? (Y/N)");
IsDemoMode = Console.ReadLine();
if (IsDemoMode == "Y")
{
// Demo code...
} else
{
// Non-Demo Code...
};
}
}
}
UPD. And it is more recommended to use Equals in such cases. So you can ignore case if you want, etc.
namespace default {
class test {
static void Main() {
Console.Clear();
string IsDemoMode;
Console.WriteLine("Activate Demo Mode? (Y/N)");
IsDemoMode = Console.ReadLine();
if (IsDemoMode.Equals("Y", StringComparison.InvariantCultureIgnoreCase))
{
// Demo code...
} else
{
// Non-Demo Code...
};
}
}
}
change the code to
if(IsDemoMode.ToLower() == "y")
{
// Demo code...
}
else
{
// Non-Demo Code...
}
You should use == instead of = in your if :
if (IsDemoMode == "Y")
{
//Demo mode
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 5 years ago.
Improve this question
Why, when I am running this code, does the question from the 2nd method repeat?
using System;
namespace mdisafmidf
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("Hello world!");
CallMethod0();
Console.WriteLine(CallMethod0());
Console.ReadKey();
}
public static string CallMethod0()
{
string x;
Console.WriteLine("Do you agree this is a good day?");
Console.WriteLine("a)Yes b)No");
x = Console.ReadLine();
if (x == "Yes")
{
return ("Of course this is a good day");
}
else
{
return ("Oh, try and stay more positive!");
}
}
}
}
You're calling the method twice, so it's running twice.
CallMethod0();
Console.WriteLine(CallMethod0());
When you run CallMethod0, it returns a string. You need to store the result to a string variable, and then Console.Write the variable. Since you have the method call in there twice, it is running twice.
In other words, change it to:
public static void Main(string[] args)
{
Console.WriteLine("Hello world!");
string result = CallMethod0(); // store the result like this
Console.WriteLine(result); // print the result - don't call the method again
Console.ReadKey();
}
Just modify your code to be like this:
var message = CallMethod0();
Console.WriteLine(message);
You are using CallMethod0() twice.
Above you have CallMethod0(); and Console.WriteLine(callMethod0());
If you remove CallMethod0(); it works fine.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Heyy,
I get this error:
Error 2 Cannot implicitly convert type 'System.Collections.Generic.List' to 'Hilversum.Geluidsfragment
At this line:
Geluidsfragment fragment = bgExperience.GetFragmenten(item)
In this code:
private void info_MouseDoubleClick(object sender, MouseEventArgs e)
{
int index = this.info.IndexFromPoint(e.Location);
string item = info.Items[index].ToString();
tbFragmentNr.Text = item;
Geluidsfragment fragment = bgExperience.GetFragmenten(item);
try
{
lbAfspeelInfo.Text = fragment.AlsString();
fragment.Play();
}
catch (NullReferenceException ex)
{
MessageBox.Show("Nummer bestaat niet");
}
}
This is the GetFragmenten method:
public List<Geluidsfragment> GetFragmenten(String p)
{
List<Geluidsfragment> resultaten = new List<Geluidsfragment>();
foreach (Geluidsfragment fragment in fragmenten)
if (fragment.Titel.IndexOf(p) != -1)
resultaten.Add(fragment);
return resultaten;
}
This is AlsString Methode:
public String AlsString()
{
return "Nr " + nr + ": " + titel + " - " + TijdsduurString;
}
Please help me :(
You're calling a function that returns a
public List<Geluidsfragment> GetFragmenten(String p)
{
//...
}
But you're assigning it to a variable that doesn't hold a List and instead holds a single instance:
Geluidsfragment fragment = bgExperience.GetFragmenten(item);
should be:
List<Geluidsfragment> fragmenten = bgExperience.GetFragmenten(item);
EDIT: From there you'd do something like:
foreach (Geluidsfragment fragment in fragmenten)
{
fragment.Play();
}
I think there's a more fundamental problem though. It looks like you're wanting to play an audio clip when something is double-clicked...but your GetFragmenten function returns multiple clips. Is this really what you want?