본문 바로가기

카테고리 없음

[C#] Left, Right, Mid 함수

반응형






Left

public string Made_Right(string Text, int TextLength) 
{
	string ConvertText;

	if (Text.Length < TextLength)
	{
		TextLength = Text.Length;
	}
	
	ConvertText = Text.Substring(Text.Length - TextLength, TextLength);
	return ConvertText;
}

Right
public string Made_Left(string Text, int TextLength)
{
	string ConvertText;

	if (Text.Length < TextLength)
	{
		TextLength = Text.Length;
	}

	ConvertText = Text.Substring(0, TextLength);
	return ConvertText;
}

Mid
public string Made_Left(string Text, int StartStr, int EndStr)
{
	string ConvertText;
	if (StartStr < Text.Length || EndStr < Text.Length)
	{
                ConvertText = Text.Substring(StartStr, EndStr);
		return ConvertText;
	}
        else
        {
                return Text;
        }
}


반응형