Answer the question
In order to leave comments, you need to log in
What could be the error when replacing in a string?
private string guidToName(string src)
{
Regex reg1 = new Regex("cad[0-9a-f]{5}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}");
Regex reg2 = new Regex("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}");
string str = src;
while (true)
{
if (reg1.IsMatch(str))
{
string oldStr=reg1.Match(str).ToString();
string newStr =session.GetAttributeType(new Guid(reg1.Match(str).ToString())).Name;
str.Replace(oldStr, newStr);
}
else if (reg2.IsMatch(str))
str.Replace(reg2.Match(str).ToString(), session.GetObject(new Guid(reg2.Match(str).ToString())).Caption);
else break;
}
return str;
}
Answer the question
In order to leave comments, you need to log in
Hello.
By the Replace method
This method does not change the value of the current instance. Instead, a new string is returned with all occurrences of oldValue replaced with newValue.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question