[Uipath] String.Format
카테고리: RPA
Replace 대신에 StringFormat을 사용해보자
Replace
위와 같은 고정 메일 형식이 있고
위와 같은 엑셀 파일이 있다고 가정하면
우리는 replace를 써서 각 해당되는 컬럼들을 바꿔줄 것이다.
strmailcontent = strmailcontent.Replace("{통화명}", row(0).Tostring)
strmailcontent = strmailcontent.Replace("{매매기준율}", row(1).Tostring)
strmailcontent = strmailcontent.Replace("{현찰살때}", row(2).Tostring)
strmailcontent = strmailcontent.Replace("{현찰팔때}", row(3).Tostring)
이런식으로 for each row를 사용하여 바꿔줄텐데 컬럼 수가 더 늘어난다면? 끔찍하다
String.Format
그래서 좀 더 간단히 바꿔줄 수 있는 String.Format을 소개하고자 한다.
우선 메일 형식을 변경해준다.
{num} : 컬럼 순서
전체적인 그림이다.
Replace라면 각 컬럼당 assign 액티비티를 늘려줘야 하지만
strContent = String.Format(strContent, CurrentRow.ItemArray)
String.Format을 사용하여 한방에 해결한 모습이다.
결과도 잘 나온다.
위와 같이 형식이 고정되어 있고 컬럼수가 많은 DT를 채워 메일 보내는 과제라면 한번 사용해보자.