Change All Dots to Comma in File

Average rating
(0 votes)

// ChangeAllDotsToCommaInFile(pathName, fileName)
// Changes all dot characters to commas in the specified file.
// You might want to do this to output a data file that represents numbers using the conventional European decimal separator.
// NOTE: This may not work for Asian text that contains double-byte characters.
Function ChangeAllDotsToCommaInFile(pathName, fileName)
	String pathName		// Name of an Igor symbolic path or ""
	String fileName			// Name of file or full path to file
 
	Variable refNum
 
	// Open source file and read the raw text from it into a string variable
	Open/Z=1/P=$pathName refNum as fileName
	if (V_flag != 0)
		return -1						// pathName and fileName do not fully specify the file to be opened
	endif
 
	FStatus refNum						// Sets V_logEOF
	Variable numBytesInFile = V_logEOF
	String text = PadString("", numBytesInFile, 0x20)
	FBinRead refNum, text				// Read entire file into variable.
 
	text = ReplaceString(".", text, ",")
 
	FSetPos refNum, 0					// Write string back to file
	FBinWrite refNum, text
 
	Close refNum
 
	return 0
End

Back to top