您好我尝试使用一些用户输入的字符串,如果字符串有引号(不知道单/双)怎么办?
具体来说,我想在字符串中存储一些R代码,例如
_webViewController = [[WebViewController alloc] init];
_webViewController.delegate = self;
_animationController = [[AnimationController alloc] initWithPresentedViewController:_webViewController
presentingView:presentingView];
_webViewController.transitioningDelegate = _animationController;
[self handleGesture:_hostViewController
presentingView:presentingView
presentedViewController:_webViewController];
- (void)handleGesture:(UIViewController *)presentingViewController
presentingView:(UIView<PresentingViewType>*)presentingView
presentedViewController:(UIViewController *)presentedViewController{
UIPanGestureRecognizer *panGesture = presentingView.panGesture;
CGPoint viewTranslation = [presentingView.panGesture translationInView:presentingView];
CGFloat progress = fabs(viewTranslation.y / 200);
switch (panGesture.state) {
case UIGestureRecognizerStateBegan:
_isInteracting = YES;
_transitionController = [UIPercentDrivenInteractiveTransition new];
[presentingViewController presentViewController:presentedViewController
animated:YES
completion:nil];
case UIGestureRecognizerStateChanged:
_shouldCompleteTransition = progress > 0.5;
[_transitionController updateInteractiveTransition:progress];
case UIGestureRecognizerStateEnded:
_isInteracting = NO;
if (_shouldCompleteTransition) {
[_transitionController finishInteractiveTransition];
} else {
[_transitionController cancelInteractiveTransition];
}
_transitionController = nil;
case UIGestureRecognizerStateFailed:
case UIGestureRecognizerStatePossible:
case UIGestureRecognizerStateCancelled:
break;
}
}
如何将此代码存储在字符串中(稍后我将使用x = 'a'
y = "b"
执行它)
更新
如果要求用户在eval(parse(text=x))
提示符下输入字符串,R会自动修复引号:
readline()
我正在考虑如何允许用户粘贴多行
答案 0 :(得分:2)
你必须要转义引号
x = '\'a\''
y = "\"b\""
或者将字符串存储在您要存储的引号的替代中
x = "'a'"
y = '"b"'
答案 1 :(得分:-2)
我想你说的是: -
null