I have $location.search('event', data); but problem is that i get in url something like this :
?event=arsenal%20fc%20
and i want to remove this spaces to get : arsenalfc
You can split the data on the spaces and rejoin it with no spaces.
data = data.split(' ').join('');
Update
Based on the conversation in the comments you might be better of replacing with a hyphen. This will give you the nice looking urls you desire whilst giving you the opportunity to re-replace them with spaces at the other end.
Remember to trim your search string first so that you don't get a trailing hyphen:
data.trim().split(' ').join('-')
Just replace the spaces with nothing:
$location.search('event', data.replace(/ /g, ''))
Related
I am trying to save category name after convert in slug
So in entity I have used setter for convert my text to slug text
protected function _setName($name)
{
return Text::slug($name);
}
After send post request in input name "আমি তোমায় ভালোবাসি"
Has got in database
ami-tomaya-bhalobasi
After make transliteratorId false
return Text::slug($name,[
'transliteratorId' => false
]);
I got output : আম-ত-ম-য-ভ-ল-ব-স
My expected result is
আমি-তোমায়-ভালোবাসি
How can I get my desire result ?
The whole point of slugs is to obtain a "safe" pure US-ASCII string. If all you seemingly want is to remove white spaces you can use a simple regular expression:
preg_replace('/\s/u', '-', 'আমি তোমায় ভালোবাসি')
However, I recommend you double-check why you think this is necessary in the first place. A properly encoded URL would display spaces as %20 anyway, which is "ugly" in a Latin script text but will get unnoticed in other scripts:
var_dump(rawurlencode('আমি তোমায় ভালোবাসি'));
string(159) "%E0%A6%86%E0%A6%AE%E0%A6%BF%20%E0%A6%A4%E0%A7%8B%E0%A6%AE%E0%A6%BE%E0%A6%AF%E0%A6%BC%20%E0%A6%AD%E0%A6%BE%E0%A6%B2%E0%A7%8B%E0%A6%AC%E0%A6%BE%E0%A6%B8%E0%A6%BF"
૮₍ • ᴥ • ₎ა・Raiden ▬▭⋱𓂅
ᘏ⑅ᘏ╭╯Welcome╰╮𓂃ᘏᗢ
・・・・・・・・・・・・・・・・・・・・・
https://discord.gg/rsCC8y7WC4
・・・・・・・・・・・・・・・・・・・・・
Join!
・・・・・・・・・・・・・・・・・・・・・
How can I pull the "discord.gg/rsCC8y7WC4" link from a text like this
console.log(invitelink) ==> discord.gg/rsCC8y7WC4
Use String.match() for this. String.match accepts a regex argument which looks like this:
let str = 'hey there this is just a random string';
let res = str.match(/random/);
//res is now ['random']
Now for your problem, you are probably looking for this:
if(msg.content.match(/discord\.gg\/.+/) || msg.content.match(/discordapp\.com\/invite\/.+/)) return msg.channel.send('Hey! You put an invite in your message!');
Now that regex may look a bit messy/complicated but the \s are to escape the character and make sure regex knows that it’s not the special character it uses, and is actually just a character part of the search. To clarify why the above example should work, here’s a little explanation:
match() returns either an array (if it gets a match) or null (if it gets no match). You are searching for the strings 'discord.gg/' followed by any characters and also checking for the string 'discordapp.com/invite/' also followed by any characters.
If this doesn’t work, please tell me.
Got quite a head-scratcher....
I'm using the VBScript function REPLACE to replace spaces in a decrypted field from a MSSQL DB with "/".
But the REPLACE function isn't "seeing" the spaces.
For example, if I run any one of the following, where the decrypted value of the field "ITF_U_ClientName_Denc" is "Johnny Carson":
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc")," ","/")
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc")," ","/")
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc"),"Chr(160)","/")
REPLACE(CSTR(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc"))," ","/")
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc")," ","/",1,-1,1)
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc")," ","/",1,-1,0)
The returned value is "Johnny Carson" (space not replaced with /)
The issue seems to be exclusively with spaces, because when I run this:
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc"),"a","/")
I get "Johnny C/rson".
Also, the issue seems to be exclusively with spaces in the decrypted value, because when I run this:
REPLACE("Johnny Carson"," ","/")
Of course, the returned value is "Johnny/Carson".
I have checked what is being written to the source of the page and it is simply "Johnny Carson" with no encoding or special characters.
I have also tried the SPLIT function to see if it would "see" the space, but it doesn't.
Finally, thanks to a helpful comment, I tried VBS REGEX searching for \s.
Set regExp = New RegExp
regExp.IgnoreCase = True
regExp.Global = True
regExp.Pattern = "\s" 'Add here every character you don't consider as special character
strProcessed = regExp.Replace(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc"), "?")
Unfortunately, strProcessed retruns "Johnny Carson" (ie. spaces not detected/removed).
If I replace regExp.Pattern = "a", strProcessed returns "Johnny C?rson".
Many thanks for your help!!
As we found, the right character code is 160, and that did the trick:
replace(..., ChrW(160), "...")
This seems to be data specific and, additionally, as an alternative you can try to get same encoding of the source script (i.e. save with Save As with Encoding), or convert received database value into a different target encoding.
I am reading data over a socket and parsing it with LibXML.
The problem that I am currently having is that sometimes there is a web link in the data which breaks the parser.
http://example.com/?key=value&key2=value
Is there any way to convert that to html characters?
Something like the above to
http://example.com/?key=value&key2=value
Example of socket data:
<node link="http://example.com/?key=value&key2=value" />
EDIT:
Found a solution that works for my problem here
You are going to have to do a pre-filter here. Contrary to other indications, search and replace just won't cut it. Consider your search side is &, which matches too much.
Construct the following finite state machine:
NORMAL:
if next matches "<" then TAG
TAG:
if next matches "![CDATA[" then CDATA
TAGSCAN
TAGSCAN:
if next matches whitespace then TAGSCAN2
if next matches > or next matches /> then NORMAL
TAGSCAN2:
if next matches whitespace then TAGSCAN2
if next matches SRC= or next matches HREF= then URL
TAGSCAN
URL:
we found an attribute with a URL in it. Do your search and replace
on the contents of the URL attribute value, advance past the URL and
go back to TAGSCAN
CDATA:
if next doesn't match ]]> then CDATA
NORMAL
I have found a nice solution using the code from
Find and Replace that uses a Find and Replace method suggested by bolov.
retval = str_replace(message, size, "&", "&");
if (!retval) {
printf("Not enough room to replace & with `&'\n");
}
I want to pass a params string include style Tag like example:
a:"<font color=blue>testing!##$%^&*()_+{}|:"<>?-=[]\;',./"
i am using decodeURI to pass the string.but still got error in extjs.
I has been checked,is a symbol % cause this error come out.
How to solve it??
Not sure that I understand your question completely, but you should probably start by escaping your string to prevent the second " from terminating your string.
// Original:
a:"<font color=blue>testing!##$%^&*()_+{}|:"<>?-=[]\;',./"
You can tell by the syntax highlighting that the original string is terminated premature.
// Escaped:
a:"<font color=blue>testing!##$%^&*()_+{}|:\"<>?-=[]\\;',./"
By using the escape character \ you can tell JS to interpret the second " as part of the string, and not a string terminator. You should also escape the \ character near the end of your string to prevent JS thinking you are using it to escape the ; character.
1)Ext.getCmp('txt').setValue(Ext.util.Format.htmlDecode(getSel.data.Message));
use Ext.util.Format.htmlDecode
2nd part is
params: {
msg: (Ext.getCmp('txt').getValue())
no need to encode
3)
Page Language="C#" AutoEventWireup="true" CodeBehind="Msg.aspx.cs" Inherits="Msg" ValidateRequest="false" %>
open Msg.aspx
add in ValidateRequest="false"