Skip to main content
Known Participant
March 25, 2024
Answered

trim space in string

  • March 25, 2024
  • 2 replies
  • 1807 views

The string extracted from indesign xml element contains ^I(tab) space. I want to trim the ^I from the string. tried Chr(9),ChrW(9),vbTab. My input string is (^I^I^IFigure^S6.1^I). This is extracted from xml file imported in indesign.

This topic has been closed for replies.
Correct answer Robert at ID-Tasker

Dim FigCapElm As InDesign.XMLElement = figureElement.XMLElements(2)
Dim splitFigCap() As String = FigCapElm.Contents.ToString.Split(vbTab)
Dim FigName As String = ""
If splitFigCap.Length > 1 Then
If splitFigCap(0).ToString.ToLower.Contains("figure") Then

FigName = splitFigCap(0).Replace(vbCr, "").Replace("&", "").Trim
FigName = Regex.Replace(FigName, Chr(9), "")
FigName = Regex.Replace(FigName, ChrW(9), "")
FigName = FigName.Replace(vbTab, "")
FigName = FigName.Replace(Chr(9), "")
FigName = Regex.Replace(FigName, "\t", "")

FigName = FigName.Replace("\u0009", "")
FigName = Regex.Replace(FigName, "\^I", "")
FigName = Regex.Replace(FigName, "^", "")
FigName = FigName.Replace(" "c, "")
FigName = Regex.Replace(FigName, "\s+", "")

End If
End If

 

 

in the attached image  figureElement.XMLElements(2) is (Figure 6.1 Schematic of an oxy-fuel combustion process. Oxygen is produced ). I have to read the Fignumber and matches the text within the frame or not. it is in (A simple block diagram representing the main components of oxy-combustion can be observed in Figure 6.1.). When I manually remove the ^I in find it finds the text. But i have to do this via code. 

 

Hope u clear my issue. Kindly do the needful.


@Aysha27550661f9sm 

 

From this:

 

Dim FigCapElm As InDesign.XMLElement = figureElement.XMLElements(2)

 

I can see that you have a reference to the whole XML and figureElement is just a reference to some "branch", right?

 

As per your screenshot - (Figure 6.1 Schematic of an oxy-fuel combustion process. Oxygen is produced ) - is an XMLElement - that is build from TWO sub XMLElements:

 

 

If you go to your text, put cursor before the "Figure" word, then keep pressing right arrow and pressing space:

>,space,>,space,>,space,>...

you will see that those XML markers start separatting - right now, you have at least TWO XML markers on top of each other:

 

So, instead of trying to split "dirty" text contents of the figureElement - just get a reference to its 1st Child - the same way as you are getting FigCapElm - 2nd element of the figureElement - I don't code  in VB.net so just guessing:

 

Dim RealFigureElement As String = FigCapElm.XMLElements(1).Contents.ToString

 

2 replies

Community Expert
March 25, 2024

There might be some encoding or formatting issue with the tab characters in your XML file. In that case, it would be helpful to see a bit more context or the structure of your XML file.

Known Participant
March 25, 2024

<!--E--><FgN aid:cstyle="FgN">Figure&#x00a0;6.1</FgN>&#x09;<!--/E--> This is xml node value

Known Participant
March 25, 2024
quote

<!--E--><FgN aid:cstyle="FgN">Figure&#x00a0;6.1</FgN>&#x09;<!--/E--> This is xml node value


By @Aysha27550661f9sm

 

But this isn't what you've shown in the opening post?

 

quote

(^I^I^IFigure^S6.1^I)


By @Aysha27550661f9sm

 

Or at least not all of it.

 

I can't "locate" what "^I" is...

 

"&#x00a0;" is of course "reguar" space

"&#x09;" is TABulator

 

But I can't see "^I" there...

 

And there are no "(" & ")" in the raw XML...

 

Can you upload more screenshots from your text - in the InDesign - with Hidden Characters Visible.

 


Figure 6.1 is read from indesign.xmlelement. But it came with ^I. sometimes it is ~I. My input xml is  

 

<title aid:pstyle="FigCap-1"><!--E--><FgN aid:cstyle="FgN">Figure&#x00a0;6.1</FgN>&#x09;<!--/E-->Schematic</title></figure>

m1b
Community Expert
Community Expert
March 25, 2024

Hi @Aysha27550661f9sm, so you want to trim the string in VB?

Known Participant
March 25, 2024

Yes I want to remove the ^I from the string. Kindly help me 

m1b
Community Expert
Community Expert
March 25, 2024

@Robert at ID-Tasker can you help here?