Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

How to trim newline character from a string variable

This is a discussion on How to trim newline character from a string variable within the QTP forums, part of the Software Testing category; Example having something like, mystring = "animals7[newline]" -> being read from a file msgbox mystring & "TESTING" The above code will display two lines animals7 TESTING How Can I trim ...

Go Back   Geeks Talk > Software Testing > QTP
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read
  #1 (permalink)  
Old 09-04-2008
Expert Member
 
Join Date: Jun 2008
Posts: 225
Thanks: 6
Thanked 13 Times in 12 Posts
learqtptesting is on a distinguished road
How to trim newline character from a string variable

Example having something like,

mystring = "animals7[newline]" -> being read from a file

msgbox mystring & "TESTING"

The above code will display two lines

animals7
TESTING

How Can I trim the newline away?
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-05-2008
Contributing Member
 
Join Date: Sep 2006
Location: CHENNAI
Posts: 48
Thanks: 5
Thanked 4 Times in 4 Posts
gokulakrishnan_k is on a distinguished road
Re: How to trim newline character from a string variable

Hi,

First calculate the length of the string received from the file.

Then using LEFT() function select the required length of characters.

Thanks

Gokulakrishnan K
Reply With Quote
  #3 (permalink)  
Old 09-09-2008
Expert Member
 
Join Date: Jun 2008
Posts: 225
Thanks: 6
Thanked 13 Times in 12 Posts
learqtptesting is on a distinguished road
Re: How to trim newline character from a string variable

Hi Gokula and others,
Your suggestion will not work well for my cases since the string in the variable is unpredictable. It can have one or more newline characters at the end.

I was looking away that I can loop through the string and verify that each character.

I think some programing language, there is/are some method to check it such as isInteger() etc.


I wonder if I can do that in QTP.
Reply With Quote
  #4 (permalink)  
Old 09-10-2008
Contributing Member
 
Join Date: Oct 2007
Posts: 30
Thanks: 0
Thanked 2 Times in 2 Posts
mgkganesh is on a distinguished road
Re: How to trim newline character from a string variable

Try with replace

Returns a string in which a specified substring has been replaced with another substring a specified number of times.

Replace(expression, find, replacewith[, start[, count[, compare]]])
Arguments
expression
Required. String expression containing substring to replace.
find
Required. Substring being searched for.
replacewith
Required. Replacement substring.
start
Optional. Position within expression where substring search is to begin. If omitted, 1 is assumed. Must be used in conjunction with count.
count
Optional. Number of substring substitutions to perform. If omitted, the default value is -1, which means make all possible substitutions. Must be used in conjunction with start.
compare
Optional. Numeric value indicating the kind of comparison to use when evaluating substrings. See Settings section for values. If omitted, the default value is 0, which means perform a binary comparison.
Reply With Quote
  #5 (permalink)  
Old 09-20-2008
Junior Member
 
Join Date: Sep 2007
Location: Baroda
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Chetan Parmar is on a distinguished road
Re: How to trim newline character from a string variable

hello
could anyone please describe the whole proccess of handling exception with one general example that can work?
Reply With Quote
Reply

  Geeks Talk > Software Testing > QTP

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Difference between String.Convert Vs String.ToString jbanx C# 6 03-24-2008 01:02 PM
Converting single character to string Geek_Guest Java 2 08-24-2007 09:42 AM
HTML/PDF - Newline Character psuresh1982 AJAX & XML 0 07-31-2007 05:37 AM
Normal Variable and the Comp-3 Variable in Cobol Geek_Guest MainFrame 0 07-04-2007 09:47 PM
Trim Function in various Databases Jim.Anderson SQL 1 03-18-2007 02:07 AM


All times are GMT -4. The time now is 04:01 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2005 - 2010 GeekInterview.com. All Rights Reserved