in url's, what's better to use to replace spaces, + or a dash? url encode does + , google recommend a dash
Tag : php , By : rhinojosa
Date : March 29 2020, 07:55 AM
hope this fix your issue urlencode() is intended for query parameters only (everything that goes after the ?). + is a special character inside the query part of the URL, and represents a literal space; literal + character needs to be percent-encoded. rawurlencode() is intended for all other URL parts, and it does not encode space as +. Dashes on the other hand are not special characters and represent themselves in the URL directly.
|
Remove special symbols and extra spaces and replace with underscore using the replace method
Date : March 29 2020, 07:55 AM
hop of those help? Your regular expression [^a-zA-Z0-9]\s/g says match any character that is not a number or letter followed by a space. Remove the \s and you should get what you are after if you want a _ for every special character. var newString = str.replace(/[^A-Z0-9]/ig, "_");
var newString = str.replace(/[^A-Z0-9]+/ig, "_");
|
Properly sort an NSString array including words starting with a dash or special symbols (for a dictionary)
Tag : iphone , By : UnKnownUser
Date : March 29 2020, 07:55 AM
may help you . to @manecosta's answer. The complete solution is rather complicated, though: #define hasDash hasPrefix:@"-"
// ...
NSMutableArray *arr = [NSMutableArray arrayWithArray:@[@"-con", @"baby",
@"context", @"zebra", @"-ar", @"-am", @"Big", @"chastity",
@"-b", @"American", @"brute"]];
[arr sortUsingComparator:^NSComparisonResult(NSString *s1, NSString *s2) {
if (![s1 hasDash] && ![s2 hasDash]) {
return [s1 caseInsensitiveCompare:s2];
} else if ([s1 hasDash] && [s2 hasDash]) {
NSString *c1 = [s1 substringFromIndex:1];
NSString *c2 = [s2 substringFromIndex:1];
return [c1 caseInsensitiveCompare:c2];
} else if ([s1 hasDash]) {
NSString *c1 = [s1 substringFromIndex:1];
if ([[[c1 substringToIndex:1] uppercaseString]
isEqualToString:[[s2 substringToIndex:1] uppercaseString]]) {
return NSOrderedAscending;
} else {
return [c1 caseInsensitiveCompare:s2];
}
} else { // if ([s2 hasDash]) {
NSString *c2 = [s2 substringFromIndex:1];
if ([[[s1 substringToIndex:1] uppercaseString]
isEqualToString:[[c2 substringToIndex:1] uppercaseString]]) {
return NSOrderedDescending;
} else {
return [s1 caseInsensitiveCompare:c2];
}
}
}];
|
java regex replace special characters and spaces with dash
Tag : java , By : Chandra P Singh
Date : March 29 2020, 07:55 AM
may help you . You're close, you just need to add a quantifier to the expression to allow it to match more than one character. /[^A-Za-z0-9]+/
"Town & Country".replaceAll("[^A-Za-z0-9]+", "-").toLowerCase();
|
String replace to replace spaces and maintain dash
Date : March 29 2020, 07:55 AM
hop of those help? I am trying to convert: , You might remove - from your RegEx pattern: function phpslug($string)
{
$slug = preg_replace('/[^a-z0-9]+/', '_', strtolower(trim($string)));
return $slug;
}
var_dump(phpslug(" Long Grain IRRI-6 White Rice "));
function phpslug($string)
{
$slug = preg_replace('/[-\s]+/', '_', strtolower(trim($string)));
return $slug;
}
var_dump(phpslug(" Long Grain IRRI-6 White Rice "));
string(28) "long_grain_irri_6_white_rice"
|