I have winform project in c# that makes math operations. The string comes like "=B10+B4*(B12-B8)"
.
And B10
represents "3", B4
represents "10" B12
represent "6" and B8
represent "2".
I want to convert this string to "=3+10*(6-2)"
. So math operation can be happened.
For solution I created three list. I succeded to make operatorList and numberRepresentList as seen below.
My problem is combining this two list with a specific order.
List<string> operatorList= new List<string>();
List<string> numberRepresentList = new List<string>();
List<string> mergedList= new List<string>();
operatorList={"=","+","*","(","-",")"}
numberRepresentList =={"3","10","6","2"}
How can i combine them with a specific order so the result will shown as:
mergedList={"=","3","+","10","*","(","6","-","2",")"}
I have searched in forms but i can not find similar one. So i created one. Thanx in advance.
Edited: Thanx to @vivek nuna. I made a list name partOfString
comesFromUser="=B10+B4*(B12-B8)"
partofString={"B10","B4","B12","B8"}
numberRepresentList =={"3","10","6","2"}
for (int i = 0; i < partOfString.Count; i++)
{
comesFromUser = comesFromUser.Replace(partOfString[i], numberRepresentList[i]);
}
There could be many ways to solve this problem.
The simplest approach, you can do this.
string output = input.Replace("B10", "3").Replace("B4", "10").Replace("B12", "6").Replace("B8", "2");