Trying to trim a string using java

626 views
Skip to first unread message

cevon carver

unread,
Jul 2, 2012, 8:34:02 AM7/2/12
to seleniu...@googlegroups.com
Hello, I am trying to trim a text message so i can compare two strings together. I am able to get the text from the id but i'm not certain how selenium syntax needs to be in java to remove certain string values. What i am trying to do is find the "-" index and erase everything after it.
 to help here is the code
<tr>
 <td>storeText</td>
 <td>id=gwt-debug-ticket_list[1][ID]</td>
 <td>CsDate</td>
        <td>string d = ${CsDate}<td>
        <td> ${CsDate} = d.indexOf('-');</td>
       // <td>d.(2);</td>
       // <td> ${CsDate} = d </td>
        <td>CsDate</td>  
</tr>
<tr>
 <td>echo</td>


The string id 20120712-0032

I am trying to get everything before the"-" but not sure how to get rid of the numbers after. 
 <td>${CsDate}</td>
 <td></td>
[6/29/2012 2:29:27 PM] Cevon  Carver: what i am trying to do is to find the index of '-' from 20120628-00055. After finding the index, i want to keep everything before '-' and delete everything after
[6/29/2012 2:29:31 PM] Cevon  Carver: Thank You in advance

Mark Collin

unread,
Jul 2, 2012, 9:03:53 AM7/2/12
to seleniu...@googlegroups.com

On possible java way would be:

 

String myString = "20120712-0032";

myString = myString.replaceFirst("-.*", "");

//myString now equals 20120712

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/AIcX1n41pVMJ.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.

cevon carver

unread,
Jul 3, 2012, 10:54:42 AM7/3/12
to seleniu...@googlegroups.com
I tried using the code, still didn't work. I know the syntax of your code is right but i'm still not familiar about selenium syntax. I tried two ways and still didn't work. The echo is still working properly though

<tr>
<td>storeText</td>
<td>id=gwt-debug-ticket_list[1][ID]</td>
<td>CsDate.replaceFirst(("-.*", ""));</td>
        <td>string d =${CsDate}; ${CsDate} = d.replaceFirst("-.*", "");</td>
</tr>
<tr>
<td>echo</td>
<td>${CsDate}</td>
<td></td>
</tr>


To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.

Vladislav Mkrtychev

unread,
Jul 3, 2012, 11:25:38 AM7/3/12
to seleniu...@googlegroups.com
Hello,

I assume you are using Selenium IDE correct?

If yes then I believe it uses Javascript and not Java.
Try this:

storeText | xpath=//*[@id="gwt-debug-ticket_list[1][ID]"] | CsDate
storeEval | javascript{var x=storedVars['CsDate']; x=x.substring(0,7); x;} | CsDate
echo | CsDate

See what will you get with this.
Hope it helps!


To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/yunU0AUg4qYJ.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.



--
Vladislav Mkrtychev

Mark Collin

unread,
Jul 3, 2012, 11:29:38 AM7/3/12
to seleniu...@googlegroups.com

It looks like you are trying to use Java code in Selenium IDE, this will not work.

 

Are you looking for a Selenium IDE solution rather than a Java solution?

 

From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of cevon carver
Sent: 03 July 2012 15:55
To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] Trying to trim a string using java

 

I tried using the code, still didn't work. I know the syntax of your code is right but i'm still not familiar about selenium syntax. I tried two ways and still didn't work. The echo is still working properly though

 

<tr>

            <td>storeText</td>

            <td>id=gwt-debug-ticket_list[1][ID]</td>

            <td>CsDate.replaceFirst(("-.*", ""));</td>

        <td>string d =${CsDate}; ${CsDate} = d.replaceFirst("-.*", "");</td>

</tr>

<tr>

            <td>echo</td>

            <td>${CsDate}</td>

            <td></td>

</tr>

 

 



On Monday, July 2, 2012 9:03:53 AM UTC-4, Mark Collin wrote:

On possible java way would be:

 

String myString = "20120712-0032";

myString = myString.replaceFirst("-.*", "");

//myString now equals 20120712

 

To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.


On Monday, July 2, 2012 9:03:53 AM UTC-4, Mark Collin wrote:

On possible java way would be:

 

String myString = "20120712-0032";

myString = myString.replaceFirst("-.*", "");

//myString now equals 20120712

 

To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.


On Monday, July 2, 2012 9:03:53 AM UTC-4, Mark Collin wrote:

On possible java way would be:

 

String myString = "20120712-0032";

myString = myString.replaceFirst("-.*", "");

//myString now equals 20120712

 

To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.


On Monday, July 2, 2012 9:03:53 AM UTC-4, Mark Collin wrote:

On possible java way would be:

 

String myString = "20120712-0032";

myString = myString.replaceFirst("-.*", "");

//myString now equals 20120712

 

To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.


On Monday, July 2, 2012 9:03:53 AM UTC-4, Mark Collin wrote:

On possible java way would be:

 

String myString = "20120712-0032";

myString = myString.replaceFirst("-.*", "");

//myString now equals 20120712

 

To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.


On Monday, July 2, 2012 9:03:53 AM UTC-4, Mark Collin wrote:

On possible java way would be:

 

String myString = "20120712-0032";

myString = myString.replaceFirst("-.*", "");

//myString now equals 20120712

 

To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.


On Monday, July 2, 2012 9:03:53 AM UTC-4, Mark Collin wrote:

On possible java way would be:

 

String myString = "20120712-0032";

myString = myString.replaceFirst("-.*", "");

//myString now equals 20120712

 

To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.

--

You received this message because you are subscribed to the Google Groups "Selenium Users" group.

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/yunU0AUg4qYJ.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.

cevon carver

unread,
Jul 3, 2012, 8:29:26 PM7/3/12
to seleniu...@googlegroups.com
Hello,

I'm just looking for a solution and thought a Java solution would be a easier way. Any input would be great.

Thank You

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/yunU0AUg4qYJ.

To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.

cevon carver

unread,
Jul 5, 2012, 8:02:57 AM7/5/12
to seleniu...@googlegroups.com
Thank You the code worked with a few syntax modifications to make it work.
Vladislav Mkrtychev

Bhavin Shah

unread,
Jun 8, 2018, 2:24:12 AM6/8/18
to Selenium Users
Hello All,

I am getting an error, kindly help me how to resolve it. (Attached)


Thanks
str error.jpg

Reed Xia

unread,
Jun 8, 2018, 4:35:38 AM6/8/18
to seleniu...@googlegroups.com
If your question is: Given String str = " 20120712-0032 ", how to make str = " 20120712".

You may want to try:

String s = "14.015_AUDI";
String[] parts = s.split("_"); //returns an array with the 2 parts
String firstPart = parts[0]; //14.015
See https://stackoverflow.com/questions/12130776/slice-string-in-java?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.

To post to this group, send email to selenium-users@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages