我正在使用视觉工作室2017,但在我们的服务器上,我们使用visual studio 2013.我一直收到一个错误,表示意外的字符$
,我做了一些研究,VS2013不支持字符串插值。是否有其他任何从捕获组中获取值?
public static String RoundParams(String flashingParams)
{
var regex = new Regex("(?<![a-zA-Z])(?<letter>[a-zA-Z])=(?<value>[^,]+)");
var result = regex.Replace(flashingParams, m =>
{
var newValue = m.Groups["letter"].Value.Any(char.IsUpper)
? RoundDoubleTo(Convert.ToDouble(m.Groups["value"].Value), 2)
: RoundDoubleTo(Convert.ToDouble(m.Groups["value"].Value), 16);
return $"{m.Groups["letter"].Value}={newValue}";
});
return result;
}
答案 0 :(得分:2)
字符串插值只是return String.Format("{0}={1}", m.Groups["letter"].Value, newValue);
的一种更好的语法:
class ClientSearch extends Component {
constructor(props){
super(props)
this.state = {
}
lowerCase = (str) => {
console.log(str);
return str;
}
test = (value, item) => {
console.log('Inside Test',item.numClientID);
let { dispatch } = this.props
dispatch(fetchClient(item.numClientID))
}
}
render() {
let value = '';
return (
<div>
<ReactAutocomplete
items={this.props.clients}
shouldItemRender={(item, value) => item.txtName.toLowerCase().indexOf(value.toLowerCase()) > -1}
getItemValue={(item) => item.txtName}
renderItem={(item, highlighted) =>
<div
key={item.numClientID}
style={{ backgroundColor: highlighted ? 'purple' : 'transparent'}}
>
{item.txtName}
</div>
}
value={this.state.selectedClient}
onChange={e => this.setState({ selectedClient: e.target.value })}
onSelect={(value, item) => this.test(value,item)}
/>
</div>
);
}
}
const mapStateToProps = (state) => {
console.log('map state', state)
return {
clients: state.client.clients
};
};
export default connect(mapStateToProps, dispatch =>
bindActionCreators(listClients, dispatch, fetchClient, dispatch)
)(ClientSearch);
答案 1 :(得分:2)
字符串插值可以通过调用return string.Format("{0}={1}", m.Groups["letter"].Value, newValue);
:
return m.Groups["letter"].Value + "=" + newValue;
或在这个简单的情况下通过字符串连接:
select email
from users u, devices d
where d.userid = u.id