我有:
var uri = window.location.href;
Run Code Online (Sandbox Code Playgroud)
这提供了 http://example.com/something#hash
什么是最好和最简单的方法来获得没有的整个路径#hash?
uri = http://example.com/something#hash
nohash = http://example.com/something
Run Code Online (Sandbox Code Playgroud)
我尝试使用location.origin+location.pathname哪个在每个浏览器中都不起作用.我尝试使用location.protocol+'//'+location.host+location.pathname这对我来说看起来像一个糟糕的解决方案.
最好和最简单的方法是什么?也许我查询location.hash并尝试从uri中substr()这个?
码:
public class Test {
public static void main(String[] args) {
String str = "University";
System.out.println(str.substring(4, 7));
}
}
Run Code Online (Sandbox Code Playgroud)
输出: ers
我真的不明白子串方法是如何工作的.索引是从0开始的吗?如果我从0开始,e是在索引4但char i是7,所以输出将是ersi.
最蠢的一件事!以下代码打印出'llo'而不是预期的'wo'.我得到了一些其他数字令人惊讶的结果.我在这里失踪了什么?
alert('helloworld'.substring(5, 2));
Run Code Online (Sandbox Code Playgroud) 如何使用JQuery获取长文本字符串(如查询字符串)以显示最多10个字符?
对不起,伙计们我是JavaScript&JQuery的新手:S
非常感谢任何帮助.
我在这一行遇到编译器错误:
UIDevice.currentDevice().identifierForVendor.UUIDString.substringToIndex(8)
Run Code Online (Sandbox Code Playgroud)
类型'String.Index'不符合协议'IntegerLiteralConvertible'
我的意图是得到子串,但是如何?
当我知道必要的索引时,我想QString从另一个人那里得到QString.例如:主字符串:"这是一个字符串".我想QString从前5个符号创建新的并获得"This".
输入:第一个和最后一个字符编号.
输出:新的QString.
如何创建它?
PS不仅前几个字母,也来自中间的字母,例如从5到8.
我需要在日志的末尾创建一个汇总表,其中包含一些在类中获得的值.该表需要以固定宽度格式打印.我已经有了这样做的代码,但我需要将字符串,双精度和整数限制为在代码中硬编码的固定宽度大小.
所以,假设我想打印一个固定宽度的表
int,string,double,string
int,string,double,string
int,string,double,string
int,string,double,string
and the fixed widths are: 4, 5, 6, 6.
Run Code Online (Sandbox Code Playgroud)
如果值超过此宽度,则需要切断最后一个字符.例如:
124891, difference, 22.348, montreal
Run Code Online (Sandbox Code Playgroud)
需要打印的字符串应该是:
1248 diffe 22.348 montre
Run Code Online (Sandbox Code Playgroud)
我想我需要在构造函数中做一些强制字符串不超过一定数量字符的东西.我可能会将双打和整数转换为字符串,因此我可以强制执行最大宽度要求.
我不知道哪个方法可以做到这一点,或者是否可以实例化一个字符串以表现出来.使用格式化程序只能使用固定格式来打印字符串,但它实际上并不会切断超过最大长度的字符.
比方说,我们给了一个字符串,比如"itiswhatitis"一个子字符串"is".我需要在原始字符串中找到第二次出现'i'字符串的索引"is".
String.indexOf("is")在这种情况下将返回2.在这种情况下,我希望输出为10.