Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
8

trim space in string

Participant ,
Mar 25, 2024 Mar 25, 2024

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.

TOPICS
EPUB , Scripting
2.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 27, 2024 Mar 27, 2024

@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:

 

RobertTkaczyk_0-1711537427697.png

 

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

...
Translate
Community Expert ,
Mar 25, 2024 Mar 25, 2024

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 25, 2024 Mar 25, 2024

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 25, 2024 Mar 25, 2024

@Robert at ID-Tasker can you help here?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 25, 2024 Mar 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 25, 2024 Mar 25, 2024

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 25, 2024 Mar 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.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 25, 2024 Mar 25, 2024

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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 25, 2024 Mar 25, 2024
quote

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>


By @Aysha27550661f9sm

 

OK.

 

The XML you are quoting - is it "raw" XML BEFORE importing, right? You need to forget about RAW XML.

 

Your "^I" things are XML markers.

 

I've selected 3x Characters - Tab, XML marker, "1":

RobertTkaczyk_0-1711361409098.png

 

So your "^I" is rather "0xFEFF".

 

RobertTkaczyk_1-1711361803748.png

 

 

BUT YOU CAN'T change <FEFF> on itself!!

RobertTkaczyk_0-1711362047154.png

"20" is now BEFORE the marker.

 

So you need to work around those markers.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 25, 2024 Mar 25, 2024

I'm able to read and show XML like a "flat" database:

 

RobertTkaczyk_1-1711362294160.png

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 25, 2024 Mar 25, 2024

can you please help me to handle this using vb.net code

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 25, 2024 Mar 25, 2024
quote

can you please help me to handle this using vb.net code


By @Aysha27550661f9sm

 

Why are you doing it in VB.net and not in VisualBasic 6 - or VBA? 

 

You need to show me your code. 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 26, 2024 Mar 26, 2024

I know VB.net only and also I have completed remaining functions in VB.net. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 26, 2024 Mar 26, 2024
quote

I know VB.net only and also I have completed remaining functions in VB.net. 


By @Aysha27550661f9sm

 

OK, but if you want my help - you need to show me your code - at least the problematic part.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 26, 2024 Mar 26, 2024

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 27, 2024 Mar 27, 2024

@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:

 

RobertTkaczyk_0-1711537427697.png

 

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:

RobertTkaczyk_1-1711537744130.png

 

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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 27, 2024 Mar 27, 2024

Yes It works. Thank You very much.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 27, 2024 Mar 27, 2024
LATEST
quote

Yes It works. Thank You very much.


By @Aysha27550661f9sm

 

You are welcome.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines