Sign in to follow this  
Followers 0
robismyname

how to remove specific character from string

4 posts in this topic

PLease read entire post before responding

I would like to remove ",1" located on the far right of my text file. Without removing ",1" that appears elsewhere in the text file. The text files shown below are executed in the autoit script.

I want the code to keep the bold ",1" but remove the bold+italicized ",1" 

Time,Mode,Band,Channel,Freq,LNA0_RX0,LockDetect
2013/07/19 20:17:13,GSM,PCS-1900, 512,1930.200, -111.27,1
2013/07/19 20:17:19,GSM,PCS-1900, 513,1930.400, -111.82,1
2013/07/19 20:17:25,GSM,PCS-1900, 514,1930.600, -111.88,1
2013/07/19 20:17:30,GSM,PCS-1900, 515,1930.800, -111.92,1
2013/07/19 20:17:36,GSM,PCS-1900, 516,1931.000, -111.93,1
2013/07/19 20:17:42,GSM,PCS-1900, 517,1931.200, -111.89,1
 
 
How do i modify my existing code that successfully removes   ",   23.00" from my text file? The autoit code for how I successfully removed 23.00 is attached. As you can tell its easier to remove "23.00' than ",1". 
 
 
Time,Mode,Band,Channel,Freq,LNA0_RX0,LNA0_RX1,TARGET_TX_PWR
2013/07/19 19:02:46,LTE,25-1930-10MHz,8040,1930.000,  -93.14,  -92.09,   23.00
2013/07/19 19:02:46,LTE,25-1930-10MHz,8041,1930.100,  -92.97,  -91.94,   23.00
2013/07/19 19:02:47,LTE,25-1930-10MHz,8042,1930.200,  -93.00,  -91.99,   23.00
2013/07/19 19:02:47,LTE,25-1930-10MHz,8043,1930.300,  -93.10,  -91.98,   23.00
2013/07/19 19:02:47,LTE,25-1930-10MHz,8044,1930.400,  -93.93,  -92.92,   23.00
2013/07/19 19:02:48,LTE,25-1930-10MHz,8045,1930.500,  -93.10,  -92.10,   23.00
2013/07/19 19:02:48,LTE,25-1930-10MHz,8046,1930.600,  -93.69,  -92.62,   23.00
2013/07/19 19:02:48,LTE,25-1930-10MHz,8047,1930.700,  -93.09,  -91.95,   23.00
2013/07/19 19:02:49,LTE,25-1930-10MHz,8048,1930.800,  -93.64,  -92.67,   23.00
 
 
 
 
 
 

post-80201-0-85706500-1374508965_thumb.p

Share this post


Link to post
Share on other sites



#Include <Array.au3>

$str = "Time,Mode,Band,Channel,Freq,LNA0_RX0,LockDetect" & @CRLF & _
"2013/07/19 20:17:13,GSM,PCS-1900, 512,1930.200, -111.27,1" & @CRLF & _
"2013/07/19 20:17:19,GSM,PCS-1900, 513,1930.400, -111.82,1" & @CRLF & _
"2013/07/19 20:17:25,GSM,PCS-1900, 514,1930.600, -111.88,1" & @CRLF & _
"2013/07/19 20:17:30,GSM,PCS-1900, 515,1930.800, -111.92,1" & @CRLF & _
"2013/07/19 20:17:36,GSM,PCS-1900, 516,1931.000, -111.93,1" & @CRLF & _
"2013/07/19 20:17:42,GSM,PCS-1900, 517,1931.200, -111.89,1"

$aSTR = stringsplit($str , @CRLF , 1)

For $i = 1 to ubound($aSTR) - 1
    If stringright($aSTR[$i] , 2) = ",1" Then
        $aSTR[$i] = stringtrimright($aSTR[$i] , 2)
    EndIf
Next

$sStripped = _ArrayToString($aSTR , @CRLF , 1)

msgbox (0, '' , $sStripped)


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

StringInStr ( "string", "substring" [, casesense [, occurrence [, start [, count]]]] )

 

Could be just me ... but the "occurrence" flag just might be what you're looking for, since it's the 2nd occurrence in each line ...

 

Failing that, you could read from the END of the string and work backwards by using a -1 for the occurrence.


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

try this

$s_test = ""
$s_test &= "2013/07/19 20:17:13,GSM,PCS-1900, 512,1930.200, -111.27,1" & @CRLF
$s_test &= "2013/07/19 20:17:19,GSM,PCS-1900, 513,1930.400, -111.82,1" & @CRLF
$s_test &= "2013/07/19 20:17:25,GSM,PCS-1900, 514,1930.600, -111.88,1" & @CRLF
$s_test &= "2013/07/19 20:17:30,GSM,PCS-1900, 515,1930.800, -111.92,1" & @CRLF
$s_test &= "2013/07/19 20:17:36,GSM,PCS-1900, 516,1931.000, -111.93,1" & @CRLF
$s_test &= "2013/07/19 20:17:42,GSM,PCS-1900, 517,1931.200, -111.89,1" & @CRLF

$s_out = StringRegExpReplace($s_test, '(?i)(.*?,.*?,.*?,.*?,.*?,.*?)(,.*?)\r\n', '$1' & @CRLF)
ConsoleWrite($s_out & @CRLF)

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0