Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
var result6 = Math.Sqrt(num1, num2);
Console.Write(name + " this is the final result of square rooting = "+ result6);
I would like to find the nth root of a number based on two user inputs. I am trying to use the Math.Sqrt() method to achieve this.
This piece of script is outputting an error No overload for method 'Sqrt' takes 2 arguments [Main2], is there a method to fix this error?
As stated in the docs the Math.sqrt(double) method only takes one parameter, no overloads.
If you meant to take the nth root, you could use Math.Pow(Double, Double) and put 1 over the second parameter, such as
Math.Pow(64, 1/3); // Cube root of 64
// Output: 4
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Will the C# function Convert.ToInt32(text) convert different words to the same int? Any links or pushes in the right direction are appreciated!
P.S.
What about anagrams?
No, Convert.ToInt32(text) will just try to parse your text to an int, like:
Convert.ToInt32("032") will return 32 as int but
Convert.ToInt32("Brian") will throw an exception.
I assume that you want to have some kind of hashing, when you say "different words to the same int".
Try GetHashCode(). It will return the same value if you call it multiple times with the same value, for example:
"Brian".GetHashCode() will always return 1635321435
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have two urls:
http://sp2013/sites/1234
and
http://sp2013/pwa/projectsites/projectdetails.aspx?projuid=1234-123-123-123456-123456
I want to get from the first url the last part (always a number)
1234
and from the second url also the last part (guid)
1234-123-123-123456-123456
How could i achieve this through RegEx or maybe with string operations in C#?
string s = "http://sp2013/sites/1234";
var firstURLlastPart = new Uri(s).Segments.Last();
string s = "http://sp2013/pwa/projectsites/projectdetails.aspx?projuid=1234-123-123-123456-123456";
var secondURLlastPart = s.Split('=').Last();
Just split at '/' and take the last chunk for the first case.
str.Split('/').Last()
Split at '=' and take last chunk for second case
str.Split('=').Last()
(?!\/|\=).[-0-9]+$
It's working for both. But it also accepts if in first example will be number in format like this:
12345-4568
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm working through string manipulation, where I need to find characters or copy some part of the string that the user has input and divide it to 3 different areas. I'm not asking anything here about code, I'll do it myself, but I was searching in the documentation that Microsoft provide about the IndexOf method and its 8 overloads and I can't really understand how to apply it. I simply can't understand what it is supposed to do.
Returns the first appearance of a specified char.
For example
string x = "Hello World";
x.indexOf("W");
it will return 6 (0 based count).
The overloads let you choose for example, where you want to start searching.. like
x.indexOf("W", 7); it will return -1 because W is at position 6 so if starts at 7 it won't find any.
I hope this helps ! the best way is to play with it
This also works with arrays.
I believe the MSDN explanation is pretty clear.
For example:
string something = "something";
int indexOfT = something.IndexOf("t"); // => returns 4
Reports the zero-based index of the first occurrence of the specified string in this instance.
So if "t" is in the fifth position of "something", 4 would be it's zero-based index.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a string that I am grabbing that is input as:
05/22/2015
Eligibility
05/06/2015
Date of Death
I need 05/06/2015. The dates will change as the program runs through a database, and I am just a little unsure on how to always be grabbing the correct one.
So you need the second date only? Is it always going to be the 3rd line? If so you can do
var secondDate = myData.Split(new [] { Environment.NewLine }, StringSplitOptions.None)[2];
If the new line isn't for certain; /n vs /r/n, use:
var secondDate = myDate.Split(Environment.Newline.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[2];
If I understand you correctly, your string has 4 lines and you want the part of the string between linebreak 2 and 3.
Search for the positions of the second and third linebreak \n and use the substring derived of these positions.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need to find the number of characters that are present in every line, within a List:
So, if for example, the string is
Ajdahnfj
Jnbafdbn
Jadnjadg
a,j,d,n are common for each line. Therefore the answer is 4.
No case sensitive is required
Regards
Here's a high level description of what I would do:
Make a collection of characters
initialize it to represent all of the characters in the first line
for each other line,
for each character in the collection, check if it's in that line. if it isn't then remove it from the list
return the resulting collection of characters