I have a string that is retrieved from a socket. I display this string as the text of a button. Some strings contains a '\' which doesn't get printed because it's an escape character. So, I want to find all '\' and replace it with a "\\" so it will show up on the button.

The code below gets an error on the first line:
ERROR: newline in constant

index = OrigString->IndexOf('\');
if (index != -1)
{
substring1 = OrigString->Substring(0,index);
substring2 = OrigString->Substring(index+1);
OrigString = String::Concat(substring1, S'\', substring2);
}

What can I do to resolve this error?
My algorithm:
1) find index of '\' in string
2) split the string into 2 strings at index
3) Concatenate string1, '\', string2

That line of code didn't work. I sent " /\ North " and had " / North " displayed on the button.

Am I to assume there's also a south, east, and west button? Why bother with the /\ at all, when you could position the buttons in a cardinal fashion?

The code for the button needs to be "/\\North".

Not at all. What you want to do is pretty simple, and should be easy to do.
So if you're using substring and such, is this SDK?
I did something similar to what you're doing (finding and making a file path) yesterday, only using CStrings.

void CGUISnoopDoc::LoadConfig()
{
	CString strPath = FilePath;
	
	for(int i=0; i<2;i++)
	{
		strPath= strPath.Left(strPath.ReverseFind('\\')+1);
		strPath+="guisnoop.cfg";					 //Append file name.
		strPath.FreeExtra();
		std::ifstream file(strPath);
		if ( file )
		{
			char line[80];
			CString fmtStr;							//Formatting string.
			while (file.getline(line, sizeof line) )
			{
				if(line[0] != '#')
				{
					fmtStr=line;
					MACaddrMAP.insert(cCStr2CStr(fmtStr.Right(17),fmtStr.Left(5)));
				}
			}
			return;
		}
		else
		{
			//Try one directory level higher.
			if(strPath.ReverseFind('\\')!=2) // Make sure that the directory isn't root, ie, C: 
				strPath= strPath.Left(strPath.ReverseFind('\\')); //remove guisnoop.cfg and \.	
			else
			{
				MessageBox(NULL,"Using MAC Addresses","No Higher Directory",MB_OK);
				return;
			}
		}
	}
	
	MessageBox(NULL,"Using MAC Addresses","Unable to open guisnoop.cfg",MB_OK); 
	return;
}

Yes, it's probably horribly inefficient as a function, but that's how I picked out the wily '\' character.

This article has been dead for over six months. Start a new discussion instead.