Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8478789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:50:38+00:00 2026-06-10T18:50:38+00:00

Can some one please help me write a code in Ruby using Watir so

  • 0

Can some one please help me write a code in Ruby using Watir so that I can read any value from a given text file based on position and use it as parameter for any field in a web application.

I am new to Ruby and have no idea how to implement this solution.

What I need is, for example, lets say there is a text file called “Test.txt” in d drive main folder. Say it has text like this

13085216660000019999

In the above text I want read the value from position 4 to 8 and i.e ‘8521’ and store it as variable and use it in a text field as given below

ie.textField(:name, “de2”).set ‘Variable got from reading the file’

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:50:39+00:00Added an answer on June 10, 2026 at 6:50 pm

    Something like this ? The [3..6] indicate the 4th position (starting from 0) until the 8th

    def my_method var
      puts var
    end
    
    File.read("read_var_from_file.txt").each_line{ |line|my_method line[3..6] }
    

    When file contents is

    13085216660000019999
    13085226660000019999
    13085236660000019999
    

    gives as output

    8521
    8522
    8523
    

    EDIT: based on the comment here another version which let you change the begin and end position by line

    def read_var file, line_nr, vbegin, vend
        IO.readlines(file)[line_nr][vbegin..vend]
    end
    
    puts read_var("read_var_from_file.txt", 0, 1, 3) #line 0, beginning at 1, ending at 3
    #=>308
    
    puts read_var("read_var_from_file.txt", 1, 3, 6)
    
    #=>8522
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can any one please help me solve this. I am resizing some flash object/embed
Possible Duplicate: JavaScript: formatting number with exactly two decimals Can some one please help
Can some one help me.. I have a script who generates code like this
I am developing a program that need read/write some files from sdcard or internal
I was wondering if anyone can help me write some code for the following
Can someone please help me with using Regex with NSPredicate? NSString *regex = @(?:[A-Za-z0-9]);
Can someone please help me to force my website to redirect to using www.
I need to write some code in PHP that performs an action only on
Having some issue with Threadpooling here that I need some help with please. I
I simply want to write some code that makes use of recursion of functions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.