You will need to change your code to something like this. String.Replace will replace any part of the string that matches the old value with the new value
foreach (var data in popUpStandardLineItem)
{
if( data.Element("Formula").Value.Trim() == olditem.Trim())
{
data.Element("Formula").Value = data.Element("Formula").Value.Replace(olditem.Trim(),newitem.Trim());
xdcBrokerFiles.Save(@f);
}
}