我有一个用户输入变量,其中包含格式为 File "<console>", line 1, in <module>
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 600, in reverse
return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 508, in _reverse_with_prefix
(lookup_view_s, args, kwargs, len(patterns), patterns))
NoReverseMatch: Reverse for 'step-autocomplete' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
的字符串,我需要将其拆分为两个不同的字符串:domain和alias。
我听说过将字符串转换为文字的地方,但我不明白这对我有什么帮助。
答案 0 :(得分:1)
写
var x = @"doamin\alias".Split('\\')
它将为您提供一个内容
的数组x[0] = "doamin"
x[1] = "alias"
如果您想要获得用户,即使未指定域名:
var user = x.Length == 2 ? x[1] : x[0];
var domain = x.Length == 2 ? x[0] : null;
答案 1 :(得分:1)
string input = @"domain\alias";
int inputindex= input.IndexOf("\\");
string domain = input.Substring(0, inputindex);
string alias = input.Substring(inputindex+1);