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

Capture data between [BRACKETS]

02-18-2012, 02:20 AM (This post was last modified: 02-18-2012 03:54 AM by nayak.)
Post: #1
Solved: 1 Year, 2 Months, 4 Weeks, 1 Day, 3 Hours, 48 Minutes, 10 Seconds ago Capture data between [BRACKETS]

Dear QTP/VBscript experts:
Here is what I am not able to do. Please help me.

1. capture specific data located in a WebElement data string
2. the WebElement has data like this ---> I am in [London] for 1 week
I need to capture London from the data string in the WebElement. Basically I want to capture data between the brackets []
3. Hold this in a variable and compare input parameter with output data which is the data between the brackets.
4. I need to use an IF THEN ELSE IF statement to compare the two variables and show what was captured in the result.

I tried to capture from WebTable but the brackets are a part of the data like [London] so I still cannot compare.
Expected data is London but actual is showing as [London]
I am not sure how to isolate this data from the rest of the data.
Please help.
Thanks.
Find all posts by this user
Quote this message in a reply
02-18-2012, 08:36 AM
Post: #2
Solved: 1 Year, 2 Months, 4 Weeks, 1 Day, 3 Hours, 48 Minutes, 10 Seconds ago RE: Capture data between [BRACKETS]
i am bit not clear with what data u get either whole "I am in [London] for 1 week" or "[London]"

anyway try below to remove brackets and get data. and do if for compare, bit easy only.
Case1:

Code:
data ="I am in [London] for 1 week"
startpos=inStr(data ,"[")
endpos =inStrRev(data,"]")
required=mid(data,startpos+1,(endpos-startpos-1))
msgbox(required)

Case2:
Code:
data="[London]"
required=mid(data,2,(Len(data)-2))
msgbox(required)
Find all posts by this user
Quote this message in a reply
02-18-2012, 01:38 PM
Post: #3
Solved: 1 Year, 2 Months, 4 Weeks, 1 Day, 3 Hours, 48 Minutes, 10 Seconds ago RE: Capture data between [BRACKETS]
@inborntester - Thanks for your contribution here. Could you please make sure to keep your code snippets under code tags? You can use 'Preview post' button and then select code tag from the tool bar. I am doing it for you this time.

Please ensure that you put your code between [code] tags for better formatting. It will help us to better help you. Check this help section to to know more.
Find all posts by this user
Quote this message in a reply
02-19-2012, 02:52 PM
Post: #4
Solved: 1 Year, 2 Months, 4 Weeks, 1 Day, 3 Hours, 48 Minutes, 10 Seconds ago At RE: Capture data between [BRACKETS]
Here is one more logic
Code:
data ="I am in [London] for 1 week"
a=split(data,"[")
b=Trim(Split(a(1),"]"))

msgbox b(0) 'London

Ramamohana Rao
Find all posts by this user
Quote this message in a reply
02-21-2012, 08:56 PM
Post: #5
Solved: 1 Year, 2 Months, 4 Weeks, 1 Day, 3 Hours, 48 Minutes, 10 Seconds ago RE: Capture data between [BRACKETS]
@inborntester - I tried Case1 Code. Its working as I wanted. Thank you very much!
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Capture data from pdf rahul1234 1 1,785 02-23-2010 02:26 PM
Last Post: Sivakumar Munganda
  How to rerieve data from .xls & compare with data in data table test71 6 2,482 03-10-2008 04:55 PM
Last Post: test71



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