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);
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 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);
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
I have the string
"{ "type" : "Stage_FF_Hot_Alerts__c"}"
I want to it be
{ "type" : "Stage_FF_Hot_Alerts__c"}
i.e. I want to remove quotes from start and end. How can I achieve this?
You could use Trim:
var a = "\"{ \"type\" : \"Stage_FF_Hot_Alerts__c\"}\"";
var b = a.Trim('"');
Console.WriteLine(a);
Console.WriteLine(b);
It will remove all leading and trailing quotation marks.
Try it online
You can also use:
var quotedString = "\"hello\"";
var unQuotedString = quotedString.TrimStart('"').TrimEnd('"');
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)
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 9 years ago.
Improve this question
This line occur new line in constant error..how can i fix this?
Locations += Environment.NewLine + " map.addOverlay(new GMarker(new GLatLng(" + Latitude + "," + Longitude + ")));";
You can not use "\" string directly in C# code, it produces "new line in constant" error. One of your variables is equal to "\", I can not directly say since the code section you have provided does not include the related initialization code.
instead of using "\", just escape the slash character using "\\".
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 want to get the previous chars from a certain char in a string.
For example: myString = "26+", so I want to get 26 without +. How can I do this?
Use Substring and IndexOf.
string str = "26+";
string requiredString = str.Substring(0, str.IndexOf('+'));
strings are immutable in C# and you have to assign the results to string itself or some other string.
The function String.Substring will do what you need.
yourString.Substring(0, keepCharactersBeforeHere);