Count how many characters [closed] - c#

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 usually never use char so sorry if it seems a noob question. I'm doing a Crypter, and wanted to do "if there's at least 4 differents char, then crypt, else don't crypt and return error"
Actual Code:
string msg = Console.ReadLine();
char[] msgToChar = msg.ToCharArray();
if(here is the problem)
{
Console.WriteLine("Crypted message: " + Crypt(msg.ToUpper()));
}
else
{
Console.WriteLine("Please enter at least 4 differentes characters.");
}

You could do this to get the distinct count of characters.
msgToChar.Distinct().Count()
So your if would be something like
if (msgToChar.Distinct().Count() >= 4)

Related

Mutiline a random string [closed]

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
I am a novice in this programming language so now I have a few problems. I have a bill where I need it to find the "/" character and then the string must be automatically carriage return
For example, I have the following string of characters:
BL4444 / BL5555 / BL6666
I need it to be:
BL4444 /
BL5555 /
BL6666
Replace / (slash and space) with / and new line:
String.Replace and Environment.NewLine:
var str = "BL4444 / BL5555 / BL6666";
str = str.Replace("/ ", "/" + Environment.NewLine);

Convert string with leading zeros to a number [closed]

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 3 years ago.
Improve this question
I've got a bit of a challenge. I have a string which contains of 11 characters, the first 10 denotes an amount, and the last one is a letter or special letter, which represents a value to add.
For example if I got
0000000400A
this means
400 + 2
So the result should be
402
I can't figure out how to do this. Any ideas?
Something like this?
// Setup
var dict = new Dictionary<char, int>();
dict.Add('A', 2);
dict.Add('B', 3);
dict.Add('C', 4);
dict.Add('D', 5);
var str = "0000000400A";
// This is what you need
var result = Convert.ToInt32(str.Substring(0, 10)) + dict[str[10]];
Console.WriteLine(result);

Split string on every 500 values with comma [closed]

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 4 years ago.
Improve this question
how to split this string on every 500 values ending in comma
string val= "1,2,3,4,5,.....................,2000,2001";
//Solution
[1,2,3,...,500]
[501,502,503,...,1000]
[1001,1002,...,1500]
You can match the string with the following regex instead (where 499 is 500 minus 1):
(?:[^,]+,){0,4}[^,]+
Demo (for splitting at every 5 commas here): https://regex101.com/r/nbRxdv/2
Assuming by "no loops" you mean you're happy to let LINQ use loops internally, maybe something like this:
string s = "your,comma,string";
string[] ss = s.Split(',');
Print500(ss, 0);
private void Print500(IEnumerable<string> ies, int skip)
{
if (skip > ies.Count())
return;
Console.Out.WriteLine(string.Join(",", ies.Skip(skip).Take(500)));
Print500(ies, skip + 500);
}
I haven't run it, so it might have some minor issues..

How can i generate unique number as format XXXX-XXXX-XXXX using c# [closed]

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
I want to generate number as format above and I try to use UUID() and GUID() but it is not what I want(difference format and it is hexadecimal not number)
anyone have any idea or logic to do it?
The simplest way to generate 1000000000000 unique numbers is just an ever-increasing sequence:
long i = 42; // whatever
string key = $"{i / 100000000:0000}-{(i / 10000) % 10000:0000}-{i % 10000:0000}";
The next time, increase i before generating the key.

how to remove particumar letter combination from a string in c#? [closed]

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 have a string like below
he/a0h/a0dv/a0jks
I would like to be string become as below.
hehdvjks
Need to remove the "/a0" from the string.
The String.Replace method is what you're looking for, just do a;
String myString = "he/a0h/a0dv/a0jks"
myString = myString.Replace("/a0", "")
It'll return a modified 'myString' with all occurrences of the old value ("/a0") replaced with a new value (blank in this case).
The MSDN reference for String.Replace can be found at:
http://msdn.microsoft.com/en-us/library/fk49wtc1%28v=vs.110%29.aspx
var result = "he/a0h/a0dv/a0jks".Replace("/a0", string.Empty);

Categories