# String spliting

**URL:** <https://rubytalk.org/t/string-spliting/68510>\
**Category:** ruby-talk\
**Created:** [26 September 2013 14:04 UTC](https://rubytalk.org/t/string-spliting/68510 "2013-09-26T14:04:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [26 September 2013 14:04 UTC](https://rubytalk.org/t/string-spliting/68510/1 "2013-09-26T14:04:01Z")

</div>

data = "\<input type=\"password\" value=\"hoax\"\>"

spl = data.split("\"password\"")

The first example works exactly like it should, but when i'm loading the  
same line from file it doesn't, even though they are both strings.

Here is the second example

fp = File.open('file','r').read

spl = data.split(/\\"password\"")

How come i can't use the first approach? Is there really difference  
between string and a string?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Ryan\_Davis1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/ryan_davis1/32/1848_2.png) [@Ryan\_Davis1](https://rubytalk.org/u/Ryan_Davis1)\
**Post date:** [26 September 2013 18:05 UTC](https://rubytalk.org/t/string-spliting/68510/2 "2013-09-26T18:05:14Z")

</div>

\\ -\> \

> **···**
>
> On Sep 26, 2013, at 7:04, Michael James \<lists@ruby-forum.com\> wrote:
> 
> > spl = data.split(/\\"password\"")

---

<div class="post-metadata">

**Author:** ![Chris6](https://avatars.discourse-cdn.com/v4/letter/c/b2d939/32.png) [@Chris6](https://rubytalk.org/u/Chris6)\
**Post date:** [26 September 2013 18:13 UTC](https://rubytalk.org/t/string-spliting/68510/3 "2013-09-26T18:13:43Z")

</div>

and add / to mark the end of the RegEx

> **···**
>
> On Thu, Sep 26, 2013 at 2:05 PM, Ryan Davis \<ryand-ruby@zenspider.com\>wrote:
> 
> > On Sep 26, 2013, at 7:04, Michael James \<lists@ruby-forum.com\> wrote:
> > 
> > \> spl = data.split(/\\"password\"")
> > 
> > \\ -\> \

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [29 September 2013 08:32 UTC](https://rubytalk.org/t/string-spliting/68510/4 "2013-09-29T08:32:24Z")

</div>

PS: dont use  
File.open('file','r').read

because it holds the FilePointer Open, use

File.read('file')

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
