我用降雨量以毫米为单位描述天气并将其转换为英寸。我已经计算出以英寸为单位的降雨量并将其替换为字符串。因为描述还有其他数字,我想只替换我转换的数字的第一个实例(降雨首先列出)。
weatherConverted = weatherConverted.stringByReplacingOccurrencesOfString("\(precipitationInMillimeters)", withString: "\(precipitationInInches)")
precipitationInMillimeters
是一个整数,因此是转义序列。我知道函数rangeOfString(_:)
将返回我放入其中的字符串的第一个实例的范围,但我不知道调用该函数并使其返回到range参数的正确语法。 / p>