반응형

string.format() 은 다양한 포맷형태를 변환하여 문자열을 나타내 주는데요 

만약 아래와같이 수식 문자열은 어덯게 처리해야할까요 ? 

 

string TestExpression = "(A-B)*C";

 

 

string.format으로는 활용하기엔 힘드는것처럼 보입니다. 

DataTable 클래스를 활용하면 된다고 하기 한번 테스트 해보앗습니다.

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
void Start()
    {   
        //예시수식
        string TestExpression = "(A-B)*C";
 
        //Table 생성
        DataTable table = new DataTable();
 
        //table에 해당 열을 생성
        table.Columns.Add("A"typeof(int));
        table.Columns.Add("B"typeof(int));
        table.Columns.Add("C"typeof(int));
        table.Columns.Add("Result"typeof(int));
 
        //Result 열에 수식을 입력
        table.Columns["Result"].Expression = TestExpression;
 
        //해당 열의 행에 값을입력
        DataRow row = table.Rows.Add();
        row["A"= 31;
        row["B"= 5;
        row["C"= 1;
 
        //테이블 로드하고 로드끝내기
        table.BeginLoadData();
        table.EndLoadData();
 
        //Result 열의 행값을 
        int a = (int)row["Result"];
 
        Debug.Log(a);
        //출력값 : 26
       
 
    }
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs

 

 

위코드를 엑셀로 표식화 해보앗습니다

 

 

 

TableData로 이용하니 해당수식을 잘 계산되서 나오네요 

 

이제 이걸 잘 함수화 시키면되겟네요 

 

 

 

 

반응형

+ Recent posts