×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Split multiple lines of string in separate string
2

Split multiple lines of string in separate string

Split multiple lines of string in separate string

(OP)
Shortly, I want to make a spelling checker for text in drawings.
The problem that I have is that most of my text is made of multiple lines.
How can I split the multiple lines of text in separate strings (catscript)?
I was thinking that something like this should work, but it doesn't:
array = Split(text, ""vbcrlf")

I want to make from multiple lines of text, single lines of text and after that I will be able to compare the text from the drawings with some .txt files.

Any kind of help is highly appreciated.

PS
I use Catia V5.R16 on a Unix workstation.



RE: Split multiple lines of string in separate string

why not just to copy a text from a verified txt file?

RE: Split multiple lines of string in separate string

(OP)
I did not explained it very good, sorry.
I have some text from a database that I can save it as .txt file. This is my master text that I know that is good.
I can read this text file using a V5 catscript and I made an array with all of this text.

Now I need to compare the text that is added manually in some V5 drawings with the master text from the array.
I can loop through all of the existing views and texts from V5 drawings, in order to compare it with my master array but I have a problem.
Some of the text from the V5 drawings is made from multiple lines of text and each line of text represent one element that I need to check.
For example I can see in the V5 drawing, a text line this:
text1
text2
When I read with the catscript above text, it gives me a single string with two lines.
I would like to make from this string with two lines, two separate strings that I can compare with my master array.
I was thinking that I can make from a string with two lines, two separate strings using the split function:
array = Split(text, ""vbcrlf"), using as separator the new line "vbcrlf". I do not understand why this does not work.
This is my question, probably it seems stupid, I do not know how to split a string with many lines.




RE: Split multiple lines of string in separate string

(OP)
By the way, the method that I use now is to export all the text from V5 drawing, to a text file and after that to manipulate with the excel in order to find differences with a master database. It works but it is a little bit stupid, I find the differences one time in excel and after that I need to search for the text manually in the V5 drawing :)
Now I want to do it it the other way around, to take the text from the database and manipulate it with the V5 catscript.

RE: Split multiple lines of string in separate string

(OP)
One more mention, the V5 drawing are actually V4 drawings imported into V5. This is how this multiple text with multiple line are generated. I tried to make directly in V5 a text that has many lines and I have no idea how, strange ...

RE: Split multiple lines of string in separate string

Don't put quotes around vbcrlf...split should work.

array = Split(text, vbcrlf)

RE: Split multiple lines of string in separate string

(OP)
array = Split(text, vbcrlf) does not work :(

I attached a example drawing and this is the code that I had used:

CODE -->

Sub CATMain()
	Dim arrManyLines
	Set oDrwDocument = CATIA.ActiveDocument
	Set oDrwView = oDrwDocument.Sheets.Item(1).views 
	For i = 1 To oDrwView.Count
		Set CurrentView = oDrwView.Item(i)
		'Skip the background view (Title block)
		If CurrentView.Name <> "ZR" Then         
			For j = 1 To oDrwView.Item(i).Texts.Count 'Scan all the Texts of the Views
				strText = oDrwView.Item(i).Texts.Item(j).Text    
				 strTextNoSpace= replace(strText," ","")            
				 arrManyLines = Split(strTextNoSpace , vbcrlf)
				 msgbox arrManyLines(0)
			Next
		End If                
	Next
End Sub 

Please, take a look and help me :)
By using this code I need to see two message box with this text: 5285VB/1M and 3397VC1-A.
What am I doing wrong?

RE: Split multiple lines of string in separate string

2
Salut,

Not a simple solution but is working bigsmile ...you have to "clean" the code of all annoying messages.

CODE --> CATScript

Sub CATMain()
	Dim arrManyLines
	Set oDrwDocument = CATIA.ActiveDocument
	Set oDrwView = oDrwDocument.Sheets.Item(1).views 
	For i = 1 To oDrwView.Count
		Set CurrentView = oDrwView.Item(i)
		'Skip the background view (Title block)
		If CurrentView.Name <> "ZR" Then         
			For j = 1 To oDrwView.Item(i).Texts.Count 'Scan all the Texts of the Views
				strText = oDrwView.Item(i).Texts.Item(j).Text    
                MsgBox strText
   ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
  ' Create temporary file 
    Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
    Dim sTemp : sTemp = fso.GetSpecialFolder(2) & "\" & fso.GetTempName
    MsgBox sTemp
       ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''Write in temporary file    
    Dim oFile : Set oFile = fso.CreateTextFile(sTemp, True)
    oFile.Write strText
    oFile.Close
   ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   ''Read lines in temporary file  
    Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(sTemp, 1)
Do Until objFile.AtEndOfStream
 strLine = objFile.ReadLine
MsgBox strLine
Loop
objFile.Close
   ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Clean up
    fso.DeleteFile sTemp
    Set fso = Nothing
     Set objFSO = Nothing
			Next
		End If                
	Next
End Sub 

Regards
Fernando

https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU

RE: Split multiple lines of string in separate string

(OP)
Actually, I am happy that it is not a simple solution :)
I lost a few hours in order to find a solution and I didn't.
Thank you for your solution, it is exactly what I need.

RE: Split multiple lines of string in separate string

I'm surprised it didn't work, nice job Ferdo;)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources