Replacing certain letters with symbol - c#

I'm doing an assignment for school which includes replacing every letter except A,a,S,s,N,n in a string.
So far I figured out how to replace these letters, which is the opposite of the assignment.
Can someone help?
This is what I have rn.
string texti = null;
Console.WriteLine ("");
Console.WriteLine ("Put in your sentence ..");
texti = Console.ReadLine();
Console.WriteLine ("You entered the following ..");
Console.WriteLine (texti);
texti = texti.Replace ("a", "*").Replace ("A", "*").Replace ("s", "*").Replace ("S", "*").Replace ("N", "*").Replace ("n", "*");
Console.WriteLine ("Your new text");
Console.WriteLine (texti);
but again .. this above is the opposite of my assignment
Here I have a similar project, but this replaces everything with #
Console.WriteLine();
for (int i = 0; i < text.Length; i++)
{
newtext = newtext + "#";
}
Console.WriteLine(newtext);
Console.ReadLine();

You can use LINQ:
var letters = "AaSsNn";
var result = String.Join("", input.Select(c => letters.Any(x => x == c) ? c : '*'));

Use a simple loop to build a new string. but with some checks and modifications.
string text = Console.ReadLine();
string newText = "";
string ommit = "AaSsNn"; // should not remove these.
for (int i = 0; i < text.Length; i++)
{
if (ommit.Contains(text[i])) // if character exist in ommit.
{
newText += text[i]; // put the original
}
else
{
newText += "*"; // replace
}
}
You can use a bit longer condition instead of using string like ommit.
if(text[i].ToString().ToUpper() == "A" ||
text[i].ToString().ToUpper() == "S" ||
text[i].ToString().ToUpper() == "N")

string texti = string.Empty;
Console.WriteLine("");
Console.WriteLine("Put in your sentence ..");
texti = Console.ReadLine();
Console.WriteLine("You entered the following ..");
Console.WriteLine(texti);
foreach (char str in texti)
{
switch (str)
{
case 'A':
case 'a':
case 'S':
case 's':
case 'N':
case 'n':
{
break;
}
default:
{
texti = texti.Replace(str, '*');
break;
}
}
}
Console.WriteLine("Your new text");
Console.WriteLine(texti);

Related

How to ask until the user get specific reply in C#

{
bool stayInLoop = true;
while(stayInLoop)
{
Console.WriteLine("Enter Yor Number");
var PlusA = Console.ReadLine();
Console.WriteLine("Enter Yor Number");
var PlusB = Console.ReadLine();
if(PlusA == ';')
{
stayInLoop = false;
break;
}
else if(PlusB == ';')
{
stayInLoop = false;
break;
}
else
{
Console.WriteLine("Answer =");
Console.WriteLine(PlusA + PlusB);
}
}
}
I want to make a plus calculator, I want to let the user type more then 2 numbers, keep asking for PlusC, PlusD, until they type the symbol ; .
For example the user numbers in PlusA PlusB PlusC and in PlusD, he/she type ; so it should print PlusA + PlusB + PlusC
If he type a number in PlusD, it should ask for PlusE, until he/she type ;, it should sum up all the number before
And I want to auto the process, The program will ask for PlusA to PlusZ itself instead of int it my own, how to do that? (I know I am not saying it clearly, coz i can't find better words)
You want to add numbers until the user enters ;. You should use loops for that. Here's the complete solution that uses a for loop:
switch(exp)
{
case "+":
{
var sum = 0;
for(;;)
{
Console.WriteLine("Enter Yor Number");
var line = Console.ReadLine();
if (line == ";") break;
sum += Convert.ToInt32(line);
}
Console.WriteLine(sum);
break;
}
}
Here we repeat the part inside the loop over and over, accumulating entered numbers into sum variable until the user enters ; - that's when we end the loop with break.
Use a while loop:
switch(exp)
{
case "+":
int sum = 0;
string input = "";
do
{
Console.WriteLine("Enter your number:");
input = Console.ReadLine();
if (input != ";")
sum += int.Parse(input);
} while (input != ";");
Console.WriteLine("Answer =" + sum);
break;
}
You are having problems because you should iterate the code until your exit/end condition is met using the while statement.
switch(exp)
{
case "+":
int mySum = 0;
string userInput = "";
while(userInput != ";")
{
Console.WriteLine("Enter number to add (';' to end the sum):");
userInput = Console.ReadLine();
if (userInput != ";")
{
// Would be interesting checking if entered really is an integer, for example Int32.TyParse()
mySum = mySum + Convert.ToInt32(userInput);
}
}
Console.WriteLine("Answer =" + mySum.ToString());
break;
}
Thankyou for your reply, but is there any way to auto the process, The program will ask for PlusA to PlusZ itself instead of int it my own
bool stayInLoop = true;
while(stayInLoop)
Console.WriteLine("Enter Yor Number");
var PlusA = Console.ReadLine();
Console.WriteLine("Enter Yor Number");
var PlusB = Console.ReadLine();
if(PlusA == ';')
{
stayInLoop = false;
break;
}
else if(PlusB == ';')
{
stayInLoop = false;
break;
}
else
{
Console.WriteLine("Answer =");
Console.WriteLine(PlusA + PlusB);
}
}
and when I run this, it run out 'error CS0019' and 'error CS0139'
What you're looking for is a while() loop.
example:
bool stayInLoop = true;
while(stayInLoop) // basically means (stayInLoop == true)
{
var text = Console.ReadLine();
if(text == ';')
{
stayInLoop = false;
break; // break will stop the loop, but you can also change the variable to false to break the loop.
}
}

Printing spaces between characters for answer to hangman game in C#

My apologies for asking yet another question, but I am struggling to get the desired output for my hangman program. When the user finds a correct letter, I would like it to display a space between letters and underscores; I can only get it to output a space after a letter and not between as desired. Also, when the secretword is guessed and the user wins, I would like the secret word to be output with spaces between the letters (eg. M A R I O). I have tried using +" " in various places, but still struggling to get the desired output. Any help would be greatly appreciated.
My code is as follows...
static void Main()
{
Console.Title = ("Hangman Game");
string[] secretWords = {
"mario", /*"sonic", "thelegendofzelda", "donkeykong", "luigi",
"peach", "link", "laracroft", "bowser", "kratos",
"playstation", "nintendo", "tetris", "grandtheftauto",
"finalfantasy", "thelastofus", "ghostoftsushima", "horizonzerodawn",
"halo", "forza", "crashbandicoot", "worldofwarcraft", "callofduty",
"fortnite", "animalcrossing", "doom", "metalgearsolid", "minecraft",
"residentevil", "pacman", "spaceinvaders", "asteroids",
"streetfighter", "mortalkombat", "supermariokart", "pokemon",
"bioshock", "tombraider"*/
};
Random R = new Random();
string secretword = secretWords[R.Next(secretWords.Length)];
List<string> letterGuessed = new List<string>();
int live = 5;
Console.WriteLine("Welcome To Hangman!");
Console.WriteLine("Enter a letter to guess for a {0} Letter Word", secretword.Length);
Console.WriteLine("You Have {0} Lives remaining \n", live);
Isletter(secretword, letterGuessed);
while (live > 0)
{
string input = Console.ReadLine();
if (letterGuessed.Contains(input))
{
Console.WriteLine("You Entered Letter [{0}] Already", input);
Console.WriteLine("Try a Different Letter \n");
continue;
}
letterGuessed.Add(input);
if (IsWord(secretword, letterGuessed))
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(secretword);
Console.WriteLine("Congratulations!");
break;
}
else if (secretword.Contains(input))
{
Console.WriteLine("Good Entry\n");
string letters = Isletter(secretword, letterGuessed);
Console.Write(letters);
Console.WriteLine("\n");
}
else
{
Console.WriteLine("That Letter Is Not In My Word");
live -= 1;
Console.WriteLine("You Have {0} Lives Remaining", live);
}
Console.WriteLine();
if (live == 0)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Game Over! \nMy Secret Word is [ {0} ]", secretword);
break;
}
}
Console.ReadKey();
}
static bool IsWord(string secretword, List<string> letterGuessed)
{
bool word = false;
for (int i = 0; i < secretword.Length; i++)
{
string c = Convert.ToString(secretword[i]);
if (letterGuessed.Contains(c))
{
word = true;
}
else
{
return word = false;
}
}
return word;
}
static string Isletter(string secretword, List<string> letterGuessed)
{
string correctletters = "";
for (int i = 0; i < secretword.Length; i++)
{
string c = Convert.ToString(secretword[i]);
if (letterGuessed.Contains(c))
{
correctletters += c;
}
else
{
correctletters += "_ ";
}
}
return correctletters;
}
}
}
Console.WriteLine(string.Join(" ", secretword.ToUpper().ToCharArray()));
worked as expected. Many thanks #41686d6564

If statement problem: ignoring other statements even if its true(?)

Even if the user input matches the string operations, the statement always results to a false which in turn shows the error prompt.
pardon my code if it seems mediocre, I just started to learn programming for not less than a week. I believe my problem is too specific that's why I'm having a hard time finding a solution. Any will be appreciated.
Console.Write("What Operation?: ");
string input = Console.ReadLine();
if (input == "+")
{
op = input;
}
if (input == "-")
{
op = input;
}
if (input == "*")
{
op = input;
}
if (input == "/")
{
op = input;
}
else
{
op = "Enter a valid operation!!!";
Console.WriteLine(op);
Console.ReadLine();
}
if the user writes the correct operation: it should store it to "op" then will be used for the equation.
You can try loop: keep asking when input is not within validInputs:
// Let's organize all valid input as a collection for better
// readability and better maintenance
HashSet<string> validInputs = new HashSet<string>() {
"+", "-", "*", "/",
};
// Keep asking...
while (true) {
// $"...{string.Join(...)}..." let's be nice and let user know
// which operations are supported: "+, -, *, /"
Console.Write($"What Operation? ({string.Join(", ", validInputs)}): ");
// Trim() - let's be nice and tolerate leading / trailing spaces
string input = Console.ReadLine().Trim();
// ... until user provides a valid input (i.e. which is in validInputs)
if (validInputs.Contains(input)) {
op = input;
break;
}
Console.WriteLine("Enter a valid operation!!!");
}
The else block relates to the previous if statement, so you have:
if (input == "/")
{
op = input;
}
else
{
op = "Enter a valid operation!!!";
Console.WriteLine(op);
Console.ReadLine();
}
Which will mean the else block will execute every time the input is not equal to "/".
Instead of using lots of if statements you can use a switch statement:
Console.Write("What Operation?: ");
string input = Console.ReadLine();
string op;
switch (input)
{
case "+":
op = input;
break;
case "-":
op = input;
break;
case "*":
op = input;
break;
case "/":
op = input;
break;
default:
op = "Enter a valid operation!!!";
Console.WriteLine(op);
Console.ReadLine();
break;
}
The else in your case is an else for the if condition above it. So whenever the input is not "/" your else will fire.
To fix that you can change your 2nd to 4th if to "else if".
The 'else' block here is only related to the last 'if' block (input == '/') so any input that is not '/' will go to this else block.
What I believe you wanted to do is to perform the last check when all other checks failed. For that you'd need an 'else if':
if (input == "+")
{
op = input;
} else if (input == "-")
{
op = input;
} else if (input == "*")
{
op = input;
} else if (input == "/")
{
op = input;
}
else
{
op = "Enter a valid operation!!!";
Console.WriteLine(op);
Console.ReadLine();
}
However a better way (more readable) would be to use switch

Input must be equal to one of 5 different string values

User input must be equal to one of 5 different strings, if not the user must input again, until the input is equal to one of the 5 strings.
I wrote some code, it works the way it should if the first entered input is equal to one of the 5 strings, if it is not, the program is stuck in an endless loop.
novaDrzava.PrevladujocaVera = Console.ReadLine();
var vera = novaDrzava.PrevladujocaVera;
var prvacrkaVera = vera.Substring(0, 1);
var ostaloVera = vera.Substring(1, vera.Length - 1);
prvacrkaVera = prvacrkaVera.ToUpper();
ostaloVera = ostaloVera.ToLower();
vera = prvacrkaVera + ostaloVera;
while (true)
{
if(vera == "Krščanstvo")
{
break;
}
if (vera == "Krscanstvo")
{
break;
}
if (vera == "Hinduizem")
{
break;
}
if (vera == "Islam")
{
break;
}
if (vera == "Budizem")
{
break;
}
Console.WriteLine("Vnesite ustrezno vero");
vera = Console.ReadLine();
vera = prvacrkaVera + ostaloVera;
}
I can't fully read your code since the identifiers aren't in English. But, given the rest of your question, I think this might be what you want:
var words = new List<string>
{
"Krščanstvo",
"Krscanstvo",
"Hinduizem",
"Islam",
"Budizem"
};
while (true)
{
var input = Console.ReadLine();
if (words.Contains(input, StringComparer.InvariantCultureIgnoreCase))
break;
Console.WriteLine("Invalid selection. Please try again");
}
You forgot to re-assign the values of prvacrkaVera and ostaloVera in the loop
while (true)
{
if(vera == "Krščanstvo")
{
break;
}
if (vera == "Krscanstvo")
{
break;
}
if (vera == "Hinduizem")
{
break;
}
if (vera == "Islam")
{
break;
}
if (vera == "Budizem")
{
break;
}
Console.WriteLine("Vnesite ustrezno vero");
vera = Console.ReadLine();
prvacrkaVera = vera.Substring(0, 1);
ostaloVera = vera.Substring(1, vera.Length - 1);
prvacrkaVera = prvacrkaVera.ToUpper();
ostaloVera = ostaloVera.ToLower();
vera = prvacrkaVera + ostaloVera;
}
Use a switch statement so you can easily detect when other values are entered
while (true)
{
switch(vera)
{
case "Krscanstvo" :
break;
case "Krščanstvo" :
break;
case "Hinduizem" :
break;
case "Islam" :
break;
case "Budizem" :
break;
default :
break; //exit while loop
break;
}
}

Logic to decrease character values

I am working on a logic that decreases the value of an alphanumeric List<char>. For example, A10 becomes A9, BBA becomes BAZ, 123 becomes 122. And yes, if the value entered is the last one(like A or 0), then I should return -
An additional overhead is that there is a List<char> variable which is maintained by the user. It has characters which are to be skipped. For example, if the list contains A in it, the value GHB should become GGZ and not GHA.
The base of this logic is a very simple usage of decreasing the char but with these conditions, I am finding it very difficult.
My project is in Silverlight, the language is C#. Following is my code that I have been trying to do in the 3 methods:
List<char> lstGetDecrName(List<char> lstVal)//entry point of the value that returns decreased value
{
List<char> lstTmp = lstVal;
subCheckEmpty(ref lstTmp);
switch (lstTmp.Count)
{
case 0:
lstTmp.Add('-');
return lstTmp;
case 1:
if (lstTmp[0] == '-')
{
return lstTmp;
}
break;
case 2:
if (lstTmp[1] == '0')
{
if (lstTmp[0] == '1')
{
lstTmp.Clear();
lstTmp.Add('9');
return lstTmp;
}
if (lstTmp[0] == 'A')
{
lstTmp.Clear();
lstTmp.Add('-');
return lstTmp;
}
}
if (lstTmp[1] == 'A')
{
if (lstTmp[0] == 'A')
{
lstTmp.Clear();
lstTmp.Add('Z');
return lstTmp;
}
}
break;
}
return lstGetDecrValue(lstTmp,lstVal);
}
List<char> lstGetDecrValue(List<char> lstTmp,List<char> lstVal)
{
List<char> lstValue = new List<char>();
switch (lstTmp.Last())
{
case 'A':
lstValue = lstGetDecrTemp('Z', lstTmp, lstVal);
break;
case 'a':
lstValue = lstGetDecrTemp('z', lstTmp, lstVal);
break;
case '0':
lstValue = lstGetDecrTemp('9', lstTmp, lstVal);
break;
default:
char tmp = (char)(lstTmp.Last() - 1);
lstTmp.RemoveAt(lstTmp.Count - 1);
lstTmp.Add(tmp);
lstValue = lstTmp;
break;
}
return lstValue;
}
List<char> lstGetDecrTemp(char chrTemp, List<char> lstTmp, List<char> lstVal)//shifting places eg unit to ten,etc.
{
if (lstTmp.Count == 1)
{
lstTmp.Clear();
lstTmp.Add('-');
return lstTmp;
}
lstTmp.RemoveAt(lstTmp.Count - 1);
lstVal = lstGetDecrName(lstTmp);
lstVal.Insert(lstVal.Count, chrTemp);
return lstVal;
}
I seriously need help for this. Please help me out crack through this.
The problem you are trying to solve is actually how to decrement discreet sections of a sequence of characters, each with it's own counting system, where each section is separated by a change between Alpha and Numeric. The rest of the problem is easy once you identify this.
The skipping of unwanted characters is simply a matter of repeating the decrement if you get an unwanted character in the result.
One difficultly is the ambiguous definition of the sequences. e.g. what to do when you get down to say A00, what is next? "A" or "-". For the sake of argument I am assuming a practical implementation based loosely on Excel cell names (i.e. each section operates independently of the others).
The code below does 95% of what you wanted, however there is a bug in the exclusions code. e.g. "ABB" becomes "AAY". I feel the exclusions need to be applied at a higher level (e.g. repeat decrement until no character is in the exclusions list), but I don't have time to finish it now. Also it is resulting in a blank string when it counts down to nothing, rather than the "-" you wanted, but that is trivial to add at the end of the process.
Part 1 (divide the problem into sections):
public static string DecreaseName( string name, string exclusions )
{
if (string.IsNullOrEmpty(name))
{
return name;
}
// Split the problem into sections (reverse order)
List<StringBuilder> sections = new List<StringBuilder>();
StringBuilder result = new StringBuilder(name.Length);
bool isNumeric = char.IsNumber(name[0]);
StringBuilder sb = new StringBuilder();
sections.Add(sb);
foreach (char c in name)
{
// If we change between alpha and number, start new string.
if (char.IsNumber(c) != isNumeric)
{
isNumeric = char.IsNumber(c);
sb = new StringBuilder();
sections.Insert(0, sb);
}
sb.Append(c);
}
// Now process each section
bool cascadeToNext = true;
foreach (StringBuilder section in sections)
{
if (cascadeToNext)
{
result.Insert(0, DecrementString(section, exclusions, out cascadeToNext));
}
else
{
result.Insert(0, section);
}
}
return result.ToString().Replace(" ", "");
}
Part2 (decrement a given string):
private static string DecrementString(StringBuilder section, string exclusions, out bool cascadeToNext)
{
bool exclusionsExist = false;
do
{
exclusionsExist = false;
cascadeToNext = true;
// Process characters in reverse
for (int i = section.Length - 1; i >= 0 && cascadeToNext; i--)
{
char c = section[i];
switch (c)
{
case 'A':
c = (i > 0) ? 'Z' : ' ';
cascadeToNext = (i > 0);
break;
case 'a':
c = (i > 0) ? 'z' : ' ';
cascadeToNext = (i > 0);
break;
case '0':
c = (i > 0) ? '9' : ' ';
cascadeToNext = (i > 0);
break;
case ' ':
cascadeToNext = false;
break;
default:
c = (char)(((int)c) - 1);
if (i == 0 && c == '0')
{
c = ' ';
}
cascadeToNext = false;
break;
}
section[i] = c;
if (exclusions.Contains(c.ToString()))
{
exclusionsExist = true;
}
}
} while (exclusionsExist);
return section.ToString();
}
The dividing can of course be done more efficiently, just passing start and end indexes to the DecrementString, but this is easier to write & follow and not much slower in practical terms.
do a check if its a number if so then do a minus math of the number, if its a string then change it to char codes and then the char code minus 1
I couldn't stop thinking about this yesterday, so here's an idea. Note, this is just pseudo-code, and not tested, but I think the idea is valid and should work (with a few modifications).
The main point is to define your "alphabet" directly, and specify which characters in it are illegal and should be skipped, then use a list or array of positions in this alphabet to define the word you start with.
I can't spend any more time on this right now, but please let me know if you decide to use it and get it to work!
string[] alphabet = {a, b, c, d, e};
string[] illegal = {c, d};
public string ReduceString(string s){
// Create a list of the alphabet-positions for each letter:
int[] positionList = s.getCharsAsPosNrsInAlphabet();
int[] reducedPositionList = ReduceChar(positionList, positionList.length);
string result = "";
foreach(int pos in reducedPositionList){
result += alphabet[pos];
}
return result;
}
public string ReduceChar(string[] positionList, posToReduce){
int reducedCharPosition = ReduceToNextLegalChar(positionList[posToReduce]);
// put reduced char back in place:
positionList[posToReduce] = reducedCharPosition;
if(reducedCharPosition < 0){
if(posToReduce <= 0){
// Reached the end, reduced everything, return empty array!:
return new string[]();
}
// move to back of alphabet again (ie, like the 9 in "11 - 2 = 09"):
reducedCharPosition += alphabet.length;
// Recur and reduce next position (ie, like the 0 in "11 - 2 = 09"):
return ReduceChar(positionList, posToReduce-1);
}
return positionList;
}
public int ReduceToNextLegalChar(int pos){
int nextPos = pos--;
return (isLegalChar(nextPos) ? nextPos : ReduceToNextLegalChar(nextPos));
}
public boolean IsLegalChar(int pos){
return (! illegal.contains(alphabet[pos]));
}
enter code here
Without writing all your code for you, here's a suggestion as to how you can break this down:
char DecrementAlphaNumericChar(char input, out bool hadToWrap)
{
if (input == 'A')
{
hadToWrap = true;
return 'Z';
}
else if (input == '0')
{
hadToWrap = true;
return '9';
}
else if ((input > 'A' && input <= 'Z') || (input > '0' && input <= '9'))
{
hadToWrap = false;
return (char)((int)input - 1);
}
throw new ArgumentException(
"Characters must be digits or capital letters",
"input");
}
char DecrementAvoidingProhibited(
char input, List<char> prohibited, out bool hadToWrap)
{
var potential = DecrementAlphaNumericChar(input, out hadToWrap);
while (prohibited.Contains(potential))
{
bool temp;
potential = DecrementAlphaNumericChar(potential, out temp);
if (potential == input)
{
throw new ArgumentException(
"A whole class of characters was prohibited",
"prohibited");
}
hadToWrap |= temp;
}
return potential;
}
string DecrementString(string input, List<char> prohibited)
{
char[] chrs = input.ToCharArray();
for (int i = chrs.Length - 1; i >= 0; i--)
{
bool wrapped;
chrs[i] = DecrementAvoidingProhibited(
chrs[i], prohibited, out wrapped);
if (!wrapped)
return new string(chrs);
}
return "-";
}
The only issue here is that it will reduce e.g. A10 to A09 not A9. I actually prefer this myself, but it should be simple to write a final pass that removes the extra zeroes.
For a little more performance, replace the List<char>s with Hashset<char>s, they should allow a faster Contains lookup.
I found solution to my own answer with some other workarounds.
The calling function:
MyFunction()
{
//stuff I do before
strValue = lstGetDecrName(strValue.ToList());//decrease value here
if (strValue.Contains('-'))
{
strValue = "-";
}
//stuff I do after
}
In all there are 4 functions. 2 Main functions and 2 helper functions.
List<char> lstGetDecrName(List<char> lstVal)//entry point, returns decreased value
{
if (lstVal.Contains('-'))
{
return "-".ToList();
}
List<char> lstTmp = lstVal;
subCheckEmpty(ref lstTmp);
switch (lstTmp.Count)
{
case 0:
lstTmp.Add('-');
return lstTmp;
case 1:
if (lstTmp[0] == '-')
{
return lstTmp;
}
break;
case 2:
if (lstTmp[1] == '0')
{
if (lstTmp[0] == '1')
{
lstTmp.Clear();
lstTmp.Add('9');
return lstTmp;
}
if (lstTmp[0] == 'A')
{
lstTmp.Clear();
lstTmp.Add('-');
return lstTmp;
}
}
if (lstTmp[1] == 'A')
{
if (lstTmp[0] == 'A')
{
lstTmp.Clear();
lstTmp.Add('Z');
return lstTmp;
}
}
break;
}
List<char> lstValue = new List<char>();
switch (lstTmp.Last())
{
case 'A':
lstValue = lstGetDecrTemp('Z', lstTmp, lstVal);
break;
case 'a':
lstValue = lstGetDecrTemp('z', lstTmp, lstVal);
break;
case '0':
lstValue = lstGetDecrTemp('9', lstTmp, lstVal);
break;
default:
char tmp = (char)(lstTmp.Last() - 1);
lstTmp.RemoveAt(lstTmp.Count - 1);
lstTmp.Add(tmp);
subCheckEmpty(ref lstTmp);
lstValue = lstTmp;
break;
}
lstGetDecrSkipValue(lstValue);
return lstValue;
}
List<char> lstGetDecrSkipValue(List<char> lstValue)
{
bool blnSkip = false;
foreach (char tmpChar in lstValue)
{
if (lstChars.Contains(tmpChar))
{
blnSkip = true;
break;
}
}
if (blnSkip)
{
lstValue = lstGetDecrName(lstValue);
}
return lstValue;
}
void subCheckEmpty(ref List<char> lstTmp)
{
bool blnFirst = true;
int i = -1;
foreach (char tmpChar in lstTmp)
{
if (char.IsDigit(tmpChar) && blnFirst)
{
i = tmpChar == '0' ? lstTmp.IndexOf(tmpChar) : -1;
if (tmpChar == '0')
{
i = lstTmp.IndexOf(tmpChar);
}
blnFirst = false;
}
}
if (!blnFirst && i != -1)
{
lstTmp.RemoveAt(i);
subCheckEmpty(ref lstTmp);
}
}
List<char> lstGetDecrTemp(char chrTemp, List<char> lstTmp, List<char> lstVal)//shifting places eg unit to ten,etc.
{
if (lstTmp.Count == 1)
{
lstTmp.Clear();
lstTmp.Add('-');
return lstTmp;
}
lstTmp.RemoveAt(lstTmp.Count - 1);
lstVal = lstGetDecrName(lstTmp);
lstVal.Insert(lstVal.Count, chrTemp);
subCheckEmpty(ref lstVal);
return lstVal;
}

Categories

Resources