使用javascript检查字符串是否编码

时间:2017-10-25 17:24:47

标签: javascript jquery html encode

我的html文本框上有def m_getWebSafeString(self, dirtyAttributeName): cleanAttributeName = ''.join(dirtyAttributeName) # Deal with beginning of string... cleanAttributeName = re.sub('^[^a-zA-z]*','BEGINNING_',cleanAttributeName) # ORIGINAL REFERENCE # --- ^ --- here if "BEGINNING_" in cleanAttributeName: print ' -- NEW STRING = {}'.format(cleanAttributeName) return cleanAttributeName 而不是空格。 我正在尝试检查字符串是否已编码,即它是否为空格或 如何检查字符串是否为 的真实字符串

我试过这个但没有运气

 

2 个答案:

答案 0 :(得分:1)

这不是文本编码,而是转换为HTML实体。

要检查您是否应该查看是否存在HTML实体。以下是此类单词的完整列表:

["&nbsp","&iexcl","&cent","&pound","&curren","&yen","&brvbar","&sect","&uml","&copy","&ordf","&laquo","&not","&reg","&macr","&deg","&plusmn","&sup2","&sup3","&acute","&micro","&para","&middot","&cedil","&sup1","&ordm","&raquo","&frac14","&frac12","&frac34","&iquest","&Agrave","&Aacute","&Acirc","&Atilde","&Auml","&Aring","&AElig","&Ccedil","&Egrave","&Eacute","&Ecirc","&Euml","&Igrave","&Iacute","&Icirc","&Iuml","&ETH","&Ntilde","&Ograve","&Oacute","&Ocirc","&Otilde","&Ouml","&times","&Oslash","&Ugrave","&Uacute","&Ucirc","&Uuml","&Yacute","&THORN","&szlig","&agrave","&aacute","&acirc","&atilde","&auml","&aring","&aelig","&ccedil","&egrave","&eacute","&ecirc","&euml","&igrave","&iacute","&icirc","&iuml","&eth","&ntilde","&ograve","&oacute","&ocirc","&otilde","&ouml","&divide","&oslash","&ugrave","&uacute","&ucirc","&uuml","&yacute","&thorn","&yuml","&fnof","&Alpha","&Beta","&Gamma","&Delta","&Epsilon","&Zeta","&Eta","&Theta","&Iota","&Kappa","&Lambda","&Mu","&Nu","&Xi","&Omicron","&Pi","&Rho","&Sigma","&Tau","&Upsilon","&Phi","&Chi","&Psi","&Omega","&alpha","&beta","&gamma","&delta","&epsilon","&zeta","&eta","&theta","&iota","&kappa","&lambda","&mu","&nu","&xi","&omicron","&pi","&rho","&sigmaf","&sigma","&tau","&upsilon","&phi","&chi","&psi","&omega","&thetasym","&upsih","&piv","&bull","&hellip","&prime","&Prime","&oline","&frasl","&weierp","&image","&real","&trade","&alefsym","&larr","&uarr","&rarr","&darr","&harr","&crarr","&lArr","&uArr","&rArr","&dArr","&hArr","&forall","&part","&exist","&empty","&nabla","&isin","&notin","&ni","&prod","&sum","&minus","&lowast","&radic","&prop","&infin","&ang","&and","&or","&cap","&cup","&int","&there4","&sim","&cong","&asymp","&ne","&equiv","&le","&ge","&sub","&sup","&nsub","&sube","&supe","&oplus","&otimes","&perp","&sdot","&lceil","&rceil","&lfloor","&rfloor","&lang","&rang","&loz","&spades","&clubs","&hearts","&diams","&\"","&amp","&lt","&gt","&OElig","&oelig","&Scaron","&scaron","&Yuml","&circ","&tilde","&ndash","&mdash","&lsquo","&rsquo","&sbquo","&ldquo","&rdquo","&bdquo","&dagger","&Dagger","&permil","&lsaquo","&rsaquo","&euro"]

在字符串中进行正则表达式搜索,你会很好!

答案 1 :(得分:0)

根据答案的帮助,我发现它们是html实体,需要正则表达式,替换。

public class Destination
{
    public string FlattenableProp1 { get; set; }

    public string FlattenableProp2 { get; set; }

    public MappedEmailAddress EmailAddress1 { get; set; }

    public List<MappedEmailAddress> EmailAddresses
    {
        get
        {
            List<MappedEmailAddress> emails = new List<MappedEmailAddress>();
            if (EmailAddress1 != null) emails.Add(EmailAddress1);

            return emails;
        }
        set
        {
            if (value == null || value.Count == 0)
                EmailAddress1 = new MappedEmailAddress();
            else
                EmailAddress1 = value[0];
        }
    }
}

如果有人将此代码转换为单个函数,那将对其他人有所帮助。