- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
以下代码总是会崩溃。输入是这样的:String 1
是一个 IpAddress
(192.168.187.815
) string 2
应该是一个端口所以整个输入是 192.168.187.815,2332
。应该删除 ipAddress (string 1
) 和端口 (string 2
) 的代码如下所示:
Console.Write("String1,String2>");
string both = Console.ReadLine();
string string1 = both.Substring(0,both.IndexOf(","));
Console.WriteLine(string1.Length);
string string2 = both.Substring( string1.Length , both.Length - 1);
Console.WriteLine(string1);
Console.WriteLine(string2);
Console.Read();
有谁知道为什么它不起作用?我被要求异常(exception),所以在这里。我来自德国,有一个小问题,德语除外。我试着用谷歌翻译器翻译它,但我想我们都知道它的废话。好吧,这是原始的德国异常(exception) Der Index und die Länge müssen sich auf eine Position in der Zeichenfolge beziehen。
这是我的错误翻译:
Parametername: length索引和长度应该在字符串中的某个位置指定。参数:长度
我希望这是有道理的
最佳答案
很明显,分隔符是 ,
那么为什么要使用 Substring
使事情复杂化,为什么不继续使用 Split
,如下所示:
string[] inputParams= both.Split(',');
string ipAddress = inputParams[0];
string portNumber =inputParams[1];
String.Substring()
的第二个参数方法代表字符数(不是你的最后一个索引思想)。如果您希望再次使用 Substring
,您可以尝试如下操作:
string ipAddress = both.Substring(0,both.IndexOf(","));
string portNumber =both.Substring(both.IndexOf(",")+1)
但对于这种情况,第一个还是最好的
关于C# String.Substring 截取一个Ip Address和一个String,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45436113/
**摘要:**下面就来给大家介绍这三个函数在字符截取时的一些用法与区别。 本文分享自华为云社区《GaussDB(DWS)中的字符截取三胞胎》,作者:我站在北方的天空下 。 在GaussDB(DWS)中
我对 JSTL 标记库前缀“fn”有疑问(Eclipse Luna 中的 webapp 开发)。 我的 taglibs.jspf 如下: 和 web.xml : *.
我正在使用转发器控件和数据绑定(bind)器将数据库中的数据显示到我的网站。示例:DataBinder.Eval(Container, "DataItem.title") 有时文字太长通常我使用 su
The second argument to substring is the index to stop at (but not include), but the second argument
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 7 年前。 Improve
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 7 年前。 Improve
假设我想返回一些 needle char 'x' 之后的所有字符,来自: $source_str = "Tuex helo babe". 通常我会这样做: if( ($x_pos = strpos($
谁能告诉我,Django 模板中是否存在 PHP 中的 substr ( http://pl2.php.net/manual/en/function.substr.php ) 之类的方法? 最佳答案
有什么区别 alert("abc".substr(0,2)); 和 alert("abc".substring(0,2)); 他们似乎都输出“ab”。 最佳答案 区别在于第二个参数。 substrin
我正在尝试编写一个函数,其中一列包含一个子字符串并且不包含另一个子字符串。 在下面的示例中,如果我的行包含“某些项目”并且不包含“开销”,我希望我的函数返回 1。 row| example strin
为什么这里 substr-rw 会切断尾随的 6? #!/usr/bin/env perl6 use v6; my $str = '123'; $str ~= '.' x 30; $str ~= '4
例子如下: a = "one two three four five six one three four seven two" m = re.search("one.*four", a) 我想要的是
来自 this question ,我们对这两个变体进行基准测试, substr( $foo, 0, 0 ) = "Hello "; substr( $foo, 0, 0, "Hello " ); 在
在我使用之前: entityManagerFactory.createQuery("select p FROM Pays p where SUBSTRING(p.libeleClient, 0,1)
substring() 和 substr() 在 MySQL 中执行时给出相同的结果。那么,它们是一样的吗?其中哪一个应该优先于另一个? 最佳答案 没有区别。阅读 manual ! 关于mysql -
在我使用之前: entityManagerFactory.createQuery("select p FROM Pays p where SUBSTRING(p.libeleClient, 0,1)
substring() 和 substr() 在 MySQL 中执行时给出相同的结果。那么,它们是一样的吗?其中哪一个应该优先于另一个? 最佳答案 没有区别。阅读 manual ! 关于mysql -
我的日期格式是这样的 2010-11-15 04:28:31 我只想选择 2010-11-15 而不是 2010-11-15 04:28:31 , 使用MYSQL查询, 从 TBL 中选择 SUBST
下面您可能会看到 xslt 代码来生成单选按钮。它适用于 Firefox 和 Opera,但不适用于 arora(使用 webkit 引擎)。简而言之,我没有尝试任何其他浏览器使用 webkit 引擎
我正在尝试向字符串中插入一个单词。为此,我使用 slice 函数,但它删除了我的空格。我还尝试了 substring 和 substr。我还查看了代码,它使用数组操作,我相信这就是问题所在。我能做什么
我是一名优秀的程序员,十分优秀!