标签: strip

目标c是否具有条带标签功能?

我正在寻找一个客观的C函数(自定义或内置),从字符串中剥离html标签,类似于PHP的版本,可以在这里找到:

http://php.net/manual/en/function.strip-tags.php

任何帮助,将不胜感激!

html tags objective-c strip

1
推荐指数
1
解决办法
2766
查看次数

在Rails中创建新模型时,是否有一种在所有上使用strip的DRY方式:params?

我有一个表单来创建一个新的Contact模型.

我通过切割和粘贴手工输入值.

有时我最终会在左右两侧添加空白区域.

这是创建控制器中的内容(我有一个循环,检查我是否上传了一个vcard,显然,通常不会出现问题(虽然它可能) - 但我的大问题是我自己输入它.

 def create

    @contact = Contact.create(params[:contact])

     unless @contact.vcard.path.blank?

           paperclip_vcard = File.new(@contact.vcard.path) 

       @vcard = Vpim::Vcard.decode(paperclip_vcard).first
       @contact.title = @vcard.title
       @contact.email = @vcard.email
       @contact.first_name = @vcard.name.given
       @contact.last_name = @vcard.name.family
       @contact.phone = @vcard.telephone
       @contact.address.street1 = @vcard.address.street
       @contact.address.city = @vcard.address.locality
       @contact.address.state = @vcard.address.region
       @contact.address.zip = @vcard.address.postalcode
       @contact.company_name = @vcard.org.fetch(0)

    end

    @contact.user_id = current_user.id # makes sure every new user is assigned an ID    
    if @contact.save
      #check if need to update company with contact info
      @contact.update_company

      @contact.new_todos #create the todos for …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails strip

1
推荐指数
1
解决办法
2619
查看次数

如何检查字符串的空白或长度为零

我最近问了一个关于将值列表从txt文件转换为字典列表的问题.你可以从这里的链接看到它:在这里查看我的问题


P883, Michael Smith, 1991
L672, Jane Collins, 1992

(added)
(empty line here)
L322, Randy Green, 1992
H732, Justin Wood, 1995(/added)
^key ^name ^year of birth

===============
这个问题已经回答了,我使用了以下代码(接受的答案),它完美地运作:

def load(filename): students = {}

   infile = open(filename)
   for line in infile:
       line = line.strip()
       parts = [p.strip() for p in line.split(",")]
       students[parts[0]] = (parts[1], parts[2])
   return students 
Run Code Online (Sandbox Code Playgroud)


但是当txt文件的值中有一个行空间时(参见添加的部分)它不再起作用并且给出一个错误,说列表索引超出范围.

python dictionary split strip

1
推荐指数
1
解决办法
1万
查看次数

重写Youtube网址

我有一些YouTube网址存储在我需要重写的数据库中.

它们以这种格式存储:

$http://youtu.be/IkZuQ-aTIs0
Run Code Online (Sandbox Code Playgroud)

我需要重新编写它们看起来像这样:

$http://youtube.com/v/IkZuQ-aTIs0
Run Code Online (Sandbox Code Playgroud)

这些值存储为变量$ VideoType

我正在调用这样的变量:

$<?php if ($video['VideoType']){
$echo "<a rel=\"shadowbox;width=700;height=400;player=swf\" href=\"" . $video['VideoType'] . "\">View Video</a>";
$}?>
Run Code Online (Sandbox Code Playgroud)

我该如何重写它们?

感谢您的帮助.

php youtube rewrite strip

1
推荐指数
1
解决办法
487
查看次数

从PHP中删除逗号

我有一个存储在PHP变量中的动态值.该变量包含一串数据,表示单击了哪些复选框.它返回如下:Option1,Option2,Option3,Option4 .....

我想删除逗号所以它只是Option1 Option2 Option3 Option4 ....

我的代码:

<?php 
    $type = the_field('type_of_work'); 
    $type = str_replace(",", "",$type);
    echo $type; 
?> 
Run Code Online (Sandbox Code Playgroud)

出于某种原因,逗号仍在呈现中.知道为什么或如何解决这个问题?您知道,the_field('type_of_work')是一种从wordpress'后端提取高级自定义字段的方法,但不应该与此问题相关,因为它正在使用逗号成功重新调整字符串.有什么想法吗?

更新:我这样做的方式与此不同:

if(in_array('brand-id', get_field('type_of_work') )): 
    echo "brand-id";
endif; 

echo " ";

if(in_array('print', get_field('type_of_work') )): 
    echo "print";
endif;
Run Code Online (Sandbox Code Playgroud)

等......

php string strip str-replace

1
推荐指数
1
解决办法
5021
查看次数

jQuery/Regex:删除所有p标签

我是Regex的新手,希望有人可以帮我解决以下问题:

我有一个长字符串保存为变量.该字符串包含纯文本和HTML标记,包括.p标签.

如何使用Regex从我的字符串中删除所有p标记,包括p标记上的类和ID,但不会丢失文本内部?字符串变量可以包含一个,多个或没有p标签,但始终至少包含一些文本.

示例: 现在看起来如何:

var str = Some awesome text with a <p class='myClass'>new paragraph</p> and more text.
Run Code Online (Sandbox Code Playgroud)

应该如何看待:

var str = Some awesome text with a new paragraph and more text.
Run Code Online (Sandbox Code Playgroud)

蒂姆,谢谢你的帮助.

html javascript regex jquery strip

1
推荐指数
2
解决办法
1万
查看次数

Rails Strip方法无法正常工作

因此,以防万一有人偶然发现同一问题,我有一个字符串:

a = " I am a string with whitespace at the start and end "

有趣的是,尝试执行时a.strip,我的字符串更改为:

a = "I am a string with whitespace at the start and end"

ruby-on-rails strip gsub

1
推荐指数
1
解决办法
1924
查看次数

语法剥离是Haskell的Palindrome函数

只是为了确保没有混淆.

我不是在问如何写一个普通的回文取景器.

我知道这将是一个重复的问题.

我知道要找到你使用的回文

isPalindrome :: (Eq a) => [a] -> Bool
isPalindrome xs = xs == (reverse xs)
Run Code Online (Sandbox Code Playgroud)

对于"madamimadam",这将成为现实.

我无法弄清楚的是,对于"我是亚当女士",这个功能会回归真实.

haskell strip palindrome

1
推荐指数
1
解决办法
284
查看次数

仅在最后一个字符时如何剥离标点符号

我知道我可以.translate(None, string.punctuation)从字符串中删除标点符号。但是,我想知道是否有一种方法可以仅在它是最后一个字符时才删除标点符号。

例如: However, only strip the final punctuation.->However, only strip the final punctuation

This is sentence one. This is sentence two!->This is sentence one. This is sentence two

This sentence has three exclamation marks!!!->This sentence has three exclamation marks

我知道我可以编写一个while循环来执行此操作,但我想知道是否有一种更优雅/更有效的方法。

python string strip punctuation

1
推荐指数
1
解决办法
544
查看次数

.strip()方法不剥离神秘的空白字符

我正在从一个文件中读取一些utf-8编码数据,如下所示:

with open (filename, 'rb') as f:
    bytes= f.read(offset, length)
    #bytes is b'hello\x00\x00\x00\x00'
    text = bytes.decode('utf-8')
    #text is 'hello    '
    stripped_text = text.strip()
    #stripped_text is 'hello    '
Run Code Online (Sandbox Code Playgroud)

您可以使用简单的行重新创建它

thing = b'hello\x00\x00\x00\x00'.decode('utf8').strip()
print(thing)
#the output is 'hello    '
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,尾随的nul字符没有被剥离 - 我认为这与.strip()无法识别的'\ x00'有关,但我看起来似乎认为它应该是.是什么赋予了?我怎样才能删除这些字符而不必做一些非常笨重的事情?

我找不到解决这个问题的帖子.

python string strip

1
推荐指数
1
解决办法
42
查看次数