我想从Java中的字符串中删除尾部斜杠.
我想检查字符串是否以url结尾,如果是,我想删除它.
这是我有的:
String s = "http://almaden.ibm.com/";
s= s.replaceAll("/","");
Run Code Online (Sandbox Code Playgroud)
还有这个:
String s = "http://almaden.ibm.com/";
length = s.length();
--length;
Char buff = s.charAt((length);
if(buff == '/')
{
LOGGER.info("ends with trailing slash");
/*how to remove?*/
}
else LOGGER.info("Doesnt end with trailing slash");
Run Code Online (Sandbox Code Playgroud)
但是没有工作.
我正在尝试解析包含多个项目符号的文本文档.
我想解析具有单个换行符的子弹点,但是当找到2个或更多换行符时想要中断.
for example :
-----------------------------------
* bullet
text on new line
more text
this should be a separate block
-----------------------------------
when passed through the function, this should capture :
-----------------------------------
-> start
bullet
text on new line
more text
<- end capture
this should be a seperate block
-----------------------------------
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止,我已经编写了一个javascript函数,可以递归地解析有序/无序的mediawiki'sh列表到HTML.唯一不同的是,块在2个换行符上插入,而对于1个换行符的mediawiki方式.
function parseLists(str)
{
//How can I capture bulleted lines with less than or equal to "1" newline character?
return str.replace(/(?:(?:(?:^|\n)[\*#].*)+)/g, function (match) {
var listType = match.match(/(^|\n)#/) ? 'ol' …Run Code Online (Sandbox Code Playgroud) 我试图使用AJAX(post请求)调用eBay FindProducts API,但是遇到了以下错误:
XMLHttpRequest无法加载http://open.api.ebay.com/shopping?callname=FindProducts.Access-Control-Allow-Origin不允许来源http://localhost.com/test.php.
我的代码:
$.ajax
({
type: "POST",
url: 'http://open.api.ebay.com/shopping?callname=FindProducts',
dataType: ($.browser.msie) ? "text" : "xml",
contentType: 'application/x-javascript',
crossDomain : true,
data: {
'X-EBAY-API-APP-ID' : 'ebayAppId',
'X-EBAY-API-VERSION': '771',
'X-EBAY-API-SITEID': '0',
'X-EBAY-API-REQUEST-ENCODING': 'NV',
'X-EBAY-API-RESPONSE-ENCODING': 'json',
'QueryKeywords' : '753759971632',
'MaxEntries' : '3'
},
success: function (result) {
alert('success');
alert(result);
},
error: function (data) {
alert((data));
}
})
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个错误.
我尝试过设置dataType : jsonp(我知道正在检索XML,但要解决错误,我将其设置为jsonP).它工作正常,但jQuery无法解析XML,因为json响应是预期的.