Sign in to follow this  
Followers 0
SeF

Quick help with StringSplit

7 posts in this topic

Hello!

I'm still trying to understand how to use StringSplit properly with delimiters (from StringRegExp HelpFile).

Like, I want to split this single text:

"47.42-3-00 - Comércio varejista de material elétrico 47.53-9-00 - Comércio varejista especializado de eletrodomésticos e equipamentos de áudio e vídeo 47.54-7-01 - Comércio varejista de móveis"

Into this:

$Variable[1] = "47.42-3-00 - Comércio varejista de material elétrico "

$Variable[2] = "47.53-9-00 - Comércio varejista especializado de eletrodomésticos e equipamentos de áudio e vídeo"

$Variable[3] = "47.54-7-01 - Comércio varejista de móveis"

I'm trying to first split by using the numbers, like:

'number' & 'number' & '.' & 'number' & 'number' & '-' & 'number' & '-' & 'number' & 'number'

But, don't know how to do it.

Any ideas?

I won't post any script because still don't have any. I'm still testing some methods.. ;)

Tks!


Share this post


Link to post
Share on other sites



does it always start with 47?


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

This should give you the result you require.

#include <array.au3>
$sData = "47.42-3-00 - Comércio varejista de material elétrico 47.53-9-00 - Comércio varejista especializado de eletrodomésticos e equipamentos de áudio e vídeo 47.54-7-01 - Comércio varejista de móveis"

$sTemp = StringRegExpReplace($sData," ([0-9]{2}\.)",@CRLF & "$1")

$aRows = StringSplit($sTemp,@CRLF,3)

;Just to show result
_ArrayDisplay($aRows, "Data Split into separate Rows")

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

Here's one way without StringSplit (assuming the given pattern is consistent throughout):

#include <Array.au3>
$sStr="47.42-3-00 - Comércio varejista de material elétrico 47.53-9-00 - Comércio varejista especializado de eletrodomésticos e equipamentos de áudio e vídeo 47.54-7-01 - Comércio varejista de móveis"
$aArr=StringRegExp($sStr,'([\d.-]+\D+(?=\s\d|$))',3)
_ArrayDisplay($aArr)

Share this post


Link to post
Share on other sites

does it always start with 47?

No. Sometimes starts with 00, 01, 21 etc.

This should give you the result you require.

#include <array.au3>
$sData = "47.42-3-00 - Comércio varejista de material elétrico 47.53-9-00 - Comércio varejista especializado de eletrodomésticos e equipamentos de áudio e vídeo 47.54-7-01 - Comércio varejista de móveis"

$sTemp = StringRegExpReplace($sData," ([0-9]{2}\.)",@CRLF & "$1")

$aRows = StringSplit($sTemp,@CRLF,3)

;Just to show result
_ArrayDisplay($aRows, "Data Split into separate Rows")

Thanks!

It worked pretty well! :)

Here's one way without StringSplit (assuming the given pattern is consistent throughout):

#include <Array.au3>
$sStr="47.42-3-00 - Comércio varejista de material elétrico 47.53-9-00 - Comércio varejista especializado de eletrodomésticos e equipamentos de áudio e vídeo 47.54-7-01 - Comércio varejista de móveis"
$aArr=StringRegExp($sStr,'([\d.-]+\D+(?=\s\d|$))',3)
_ArrayDisplay($aArr)

Thanks!

Also worked pretty well! ;)

---

Thanks everyone! ;)


Share this post


Link to post
Share on other sites

"Pretty well" suggests that it didn't work quite as you needed. If you can point out what didn't behave properly, it may be an easy fix to the expression.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

"Pretty well" suggests that it didn't work quite as you needed. If you can point out what didn't behave properly, it may be an easy fix to the expression.

Sorry. I didn't used the right word. Actually, it worked perfectly! :)

I used Bowmore's script.

Here is the final script:

#include<Excel.au3>
$oExcel = _ExcelBookAttach("Pessoa Fisica.xlsb", "filename")
$i = 2
Do
    $Celula = _ExcelReadCell($oExcel, "E" & $i)
    If $Celula <> "Não informada" Then
        $sTemp = StringRegExpReplace($Celula, " ([0-9]{2}\.)", @CRLF & "$1")
        $aRows = StringSplit($sTemp, @CRLF, 1)
        If $aRows[0] <> "1" Then
            $p = 1
            $c = 0
            Do
                $oExcel.Application.Range(Chr(Asc("E") + $c) & $i).Select ;Just to watch the script "doing your job". For fun ;D
                _ExcelWriteCell($oExcel, $aRows[$p], Chr(Asc("E") + $c) & $i)
                $c = $c + 1
                $p = $p + 1
            Until $c = $aRows[0]
        EndIf
    EndIf
    $i = $i + 1
Until $i = _ExcelReadCell($oExcel, "E" & $i) = ""
;

Just changed one parameter from StringSplit because I needed to know how many arrays was splited.

It was about 160,000 Excel's Rows in less than 1 hour. I'm satisfied with the code! ;)

Anyway, thanks for the concern! ;)

Edited by SeF

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