Please ensure to include your code between [code][/code] tags while asking or replying to questions.

Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Split a String

12-23-2010, 07:26 PM (This post was last modified: 12-23-2010 08:13 PM by sudhirzpatil.)
Post: #1
Solved: 1 Year, 2 Months, 4 Weeks, 23 Hours, 10 Minutes, 44 Seconds ago Split a String

Hi All,
I want to know about Split function in qtp.

I want to split a text " New York To Goa"
I want 'New York' and 'Goa' in two separate variable.


Friends got it
text="New York TO Goa"
Myarr=split(text,"TO")
msgbox Myarr(0)
msgbox Myarr(1)
Find all posts by this user
Quote this message in a reply
12-23-2010, 09:39 PM
Post: #2
Solved: 1 Year, 2 Months, 4 Weeks, 23 Hours, 10 Minutes, 44 Seconds ago RE: Split a String
I am facing another problem with Split now.

I have captured the text = " Frankfurt TO New York"
the text come from run time datatable.
text= datatable.Value("Select_a_Flight_MercuryOutput_Text_out",dtglobalsheet)
I used following split function
Code:
Myarr=split(text,"TO")
msgbox Myarr(0)
msgbox  Myarr(1)

Here Myarr(0) displayed the value as Frankfurt TO New York ?
and Myarr(1) displayed following error.

The test run cannot continue due to an unrecoverable error.

Subscript out of range: '[number: 1]'

Line (16): "msgbox Myarr(1)".

Please find the below code
---------------------------------------------------------------------------------
Code:
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set "mercury"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("password").SetSecure "4d136083f7eb3294cfee0f9766e331cd0c781dde"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Click 34,13
For i=1 to Datatable.GetRowCount
datatable.SetCurrentRow(i)
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("fromPort").Select DataTable("p_Item", dtGlobalSheet)
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("toPort").Select DataTable("p_Item1", dtGlobalSheet)
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").Image("findFlights").Click 57,16
'Browser("Welcome: Mercury Tours").Page("Select a Flight: Mercury").WebElement("Frankfurt to New York").Output CheckPoint("Frankfurt to New York")
Browser("Welcome: Mercury Tours").Page("Select a Flight: Mercury").Output CheckPoint("Select a Flight: Mercury Tours")
text= datatable.Value("Select_a_Flight_MercuryOutput_Text_out",dtglobalsheet)
msgbox text
Dim a,b,text
Myarr=split(text,"TO")
msgbox Myarr(0)
msgbox  Myarr(1)
Browser("Welcome: Mercury Tours").Back
Next
Find all posts by this user
Quote this message in a reply
12-24-2010, 10:03 AM
Post: #3
Solved: 1 Year, 2 Months, 4 Weeks, 23 Hours, 10 Minutes, 44 Seconds ago RE: Split a String
Hi Sudhir,

Can you please provide the strings you get from the 2 outcheckpoints you applied and also make sure that the values are stored in different columns.

The split is working fine for me.

Code:
text= "Frankfurt TO New York"
Myarr=split(text,"TO")
msgbox Myarr(0)
msgbox Myarr(1)

Regards,
Manish
Find all posts by this user
Quote this message in a reply
12-24-2010, 11:10 AM
Post: #4
Solved: 1 Year, 2 Months, 4 Weeks, 23 Hours, 10 Minutes, 44 Seconds ago RE: Split a String
Hi Manish,
One slight chnage in above code is, I have not used below checkpoint.
Code:
'Browser("Welcome: Mercury Tours").Page("Select a Flight: Mercury").WebElement("Frankfurt to New York").Output CheckPoint("Frankfurt to New York")

Below code is alos working for me, if use seprately.

But if it is implemented with above script, I am surprised it give inorrect result.
For details please see below Datatable I used.

Code:
DataTable("p_Item", dtGlobalSheet)-  For Fly From parameters.
DataTable("p_Item1", dtGlobalSheet)- For Fly To parameters.
datatable.Value("Select_a_Flight_MercuryOutput_Text_out",dtglobalsheet)
- Which give me run time output value.

Now if
Fly From = New York
Fly To= Paris.
I put it in text so
text= datatable.Value("Select_a_Flight_MercuryOutput_Text_out",dtglobalsheet) = "New York To Paris"

Its working upto this.
Now I used Split function to seprate " New York To Paris" using following split function.
Myarr=split(text,"TO")
When I used following function
msgbox Myarr(0)
It still displyed the whole text . i.e. "New York To Paris" instead it should only show New York
And msgbox Myarr(1) displayed error.

Can you please let me know why this is happening.

Simpley I want to verify that
Code:
a= x and b=y where
a= DataTable("p_Item", dtGlobalSheet
b=DataTable("p_Item1", dtGlobalSheet)
x=Myarr(0)
y=Myarr(1)
Find all posts by this user
Quote this message in a reply
12-24-2010, 11:20 AM
Post: #5
Solved: 1 Year, 2 Months, 4 Weeks, 23 Hours, 10 Minutes, 44 Seconds ago RE: Split a String
Hi Sudhir,

You typed the string wrong while performing split:
The string you want to split is: "New York To Paris"
But while spliting you used "TO", it should be "To".

Regards,
Manish
Find all posts by this user
Quote this message in a reply
12-24-2010, 11:37 AM
Post: #6
Solved: 1 Year, 2 Months, 4 Weeks, 23 Hours, 10 Minutes, 44 Seconds ago RE: Split a String
Ohh ok,
Manish I will check it on and let you know.

One more problem i faced yesterday on this is
if i used
msgbox Myarr(0) It displayed the text.
But if I put above value in another variable like
a= Myarr(0) why this shows error ?
Find all posts by this user
Quote this message in a reply
12-26-2010, 09:39 AM
Post: #7
Solved: 1 Year, 2 Months, 4 Weeks, 23 Hours, 10 Minutes, 44 Seconds ago RE: Split a String
Thanks Manish,
I corrected it, and its working now. And my second query also get resolved as I am able to get both the value in
a= Myarr(0)
b= Myarr(1).

Thanks a lot.
Find all posts by this user
Quote this message in a reply
01-04-2011, 07:12 PM (This post was last modified: 01-05-2011 03:08 PM by PrasadMedepalle.)
Post: #8
Solved: 1 Year, 2 Months, 4 Weeks, 23 Hours, 10 Minutes, 44 Seconds ago RE: Split a String
Code:
Str="New York TO Goa"
'Split above string with 'TO' as delimiter
SplStr=Split(Str,"TO",-1,1)
Now SplStr is an Array with
SplStr[0]="New York" and
SplStr[1]="Goa"

Cheers,
Rajendraprasad Medepalle
Visit this user's website Find all posts by this user
Quote this message in a reply
01-04-2011, 11:22 PM
Post: #9
Solved: 1 Year, 2 Months, 4 Weeks, 23 Hours, 10 Minutes, 44 Seconds ago RE: Split a String
Hi Prasad,

Wrap-up the code and then post.

Seems you are new member to this forum, plz go thru the Posting guidelines once.

Never limit your challenges , Challenge your limits
Visit this user's website Find all posts by this user
Quote this message in a reply
01-05-2011, 03:03 PM
Post: #10
Solved: 1 Year, 2 Months, 4 Weeks, 23 Hours, 10 Minutes, 44 Seconds ago RE: Split a String
yes srikanth.. recently i joined in the forum.
for next postings will follow the posing guidelines..



Thanks,
Prasad
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Replace a string in a word document with another string rekha.naik 8 4,638 11-14-2013 12:58 PM
Last Post: pranikgarg
  Split function in string nidhishnair 13 15,589 03-02-2013 02:19 PM
Last Post: nikhilcogni
  Split Function diya 2 1,153 11-28-2012 08:49 PM
Last Post: diya
Question Deatils on Split action with Nested type sams001 0 820 10-30-2012 03:03 PM
Last Post: sams001
  split the values in url ....................... rjkmr.aiht 3 1,256 05-21-2012 06:09 PM
Last Post: Ankesh



User(s) browsing this thread: 1 Guest(s)