I ran across this in the legacy codebase:
string[] deptNo = UPC.getDept().Split(new Char[] {'.'});
...and thought this would be more straightforward:
string[] deptNo = UPC.getDept().Split('.');
...but don't want to change it if there's a possibility that characterization of the dot does something "magic" that will cause the whole spaghetti house to come slithering down if I make this change.
UPDATE
In response to the cautions given: Yes, I know what you mean about the need to proceed with utmost caution whilst thrashing about in years-old spaghetti. A seemingly innocuous change to this code:
private void comboVendor_SelectedValueChanged(object sender, EventArgs e)
{
try
{
if ((comboVendor.SelectedIndex >= 0) && (cmbVendor.Text != comboVendor.Text))
{
string t = comboVendor.Text;
t = t.Substring(0,maxVendorChar);
t = t.Substring(0,substrLen);
t = t.Trim();
cmbVendor.Text = t;
cmbVendor.Focus();
}
}
catch (Exception ex)
{
Duckbill.ExceptionHandler(ex, "frmInv.comboVendor.SelectedValueChanged");
}
}
...namely, appending "Trim()" to the instances of ".Text",caused the err msg "Specified argument was out of the range of valid values." because "maxVendorChar" was not larger than the value of the string being substringed. So I had to change it to this to get it to work:
private void comboVendor_SelectedValueChanged(object sender, EventArgs e)
{
int substrLen;
try
{
if ((comboVendor.SelectedIndex >= 0) && (cmbVendor.Text.Trim() != comboVendor.Text.Trim()))
{
string t = comboVendor.Text.Trim();
substrLen = GetLowerInt(t.Length, maxVendorChar);
t = t.Substring(0,substrLen);
t = t.Trim();
cmbVendor.Text = t;
cmbVendor.Focus();
}
}
catch (Exception ex)
{
Platypus.ExceptionHandler(ex, "frmInv.comboVendor.SelectedValueChanged");
}
}
private int GetLowerInt(int first, int second)
{
return first < second ? first : second;
}
Off in the distance, I heard a raven croaking "nevermore," but I'm not sure what he was talking about.
UPDATE 2
Whenever people note just how starchy-stringy-slippery this project is, they almost invariably recommend that I refactor it; however, as noted above, sometimes a little refactoring sets off a series of deafening explosions that makes me wish I had left ill enough alone. The real solution is to completely rewrite this project, with better methodologies and at least less-ancient technologies. That's my vision; for now, though, maintenance mode seems to be the order of the day.