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

compare 2 string equal false, open dialog

Explorer ,
Aug 17, 2013 Aug 17, 2013

Hi all,

I developpe a function who compare if a certain link is in an list. This list can be full by the user with a File.openDialog.

My function work only with link who haven't any space in the file name. I think it'is a encoding problem but i don't know how to fix this problem.

If anyone can help me I would appreciate!

Thanks you!

My code look like this:

//choose a certain file

var array_of_files = File.openDialog ("selectionner une image ou plusieurs images", get_file_filter ([".psd", ".png", ".jpg", ".eps"], "choisir une image"), true);

// add to an array, i add the decode because my file as space and i want that to display it without %

myArray.push(File.decode(array_of_files[index].name));

After I select all links and I foreach link I compare if the link is in the array myArray

var array_all_links = doc_package.links;

for(var i = 0; i<array_all_links.length; i++){

      is_link_valid (array_all_links)

}

// this function doesn't work with link with space

function is_link_valid(link_item){

    var is_link_valid = true;

    if(is_in_array(link_item.name, results.array_of_ignored_picture) ){

        is_link_valid = false;

    }

    alert(is_link_valid);

    return is_link_valid;

}

function is_in_array(myString, myArray) {

          for (x in myArray) {

                    if (myString == myArray) {

                              return true;

                    }

          }

          return false;

}

TOPICS
Scripting
2.9K
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

Community Expert , Aug 19, 2013 Aug 19, 2013

But the good question is why a string from the link in Indesign and an other from the file system is encoding different.

@Bastien – I think this is made clear from the other thread you mentioned.
To speak it out: Adobe neglected to make it work and automatically "normalize" composite characters from OSX, if you read out file names from the OS with ExtendScript.

If you would work with AppleScript, there would be no problems in this regard.

To compair the two names, one derived from OSX directly, the

...
Translate
Explorer ,
Aug 17, 2013 Aug 17, 2013

Hi,

I forget that, my values look like this after running this script:

// if I use File.decode my values look like this

var str = "Capture d’écran 2013-07-31 à 18.57.24.png";

var str2 = "Capture d’écran 2013-07-31 à 18.57.24.png";

if(str == str2){

    $.writeln(true);

}

else{

    $.writeln(false);

}

// if I doesn't use File.decode, my values are different!

var str_encode = "Capture%20d%E2%80%99%C3%A9cran%202013-07-31%20%C3%A0%2018.57.24.png";

var str_encode_2 = "Capture%20d%E2%80%99e%CC%81cran%202013-07-31%20a%CC%80%2018.57.24.png";

if(str_encode == str_encode_2){

    alert("string equal");

}

else{

    alert(str_encode == str_encode_2);

    alert("string not equal");

}

This 2 string are the same and by me this test return "false":( But if I copie this text and paste in the extendToolKit the result is true

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 ,
Aug 18, 2013 Aug 18, 2013

That's because the strings str_encode and str_encode_2 aren't the same. Do this:

// if I use File.decode my values look like this

var str = "Capture d’écran 2013-07-31 à 18.57.24.png";

var str2 = "Capture d’écran 2013-07-31 à 18.57.24.png";

if(str == str2){

    $.writeln(true);

}

else{

    $.writeln(false);

}

// if I doesn't use File.decode, my values are different!

var str_encode = encodeURI(str);

var str_encode_2 = encodeURI(str2);

if(str_encode == str_encode_2){

    alert("string equal");

}

else{

    alert(str_encode == str_encode_2);

    alert("string not equal");

}

and you get the result you were after.

Peter

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
Mentor ,
Aug 18, 2013 Aug 18, 2013

not too sure what you are doing there but try

if (str_encode.toString() == str_encode_2.toString())

Using 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
Explorer ,
Aug 18, 2013 Aug 18, 2013

Hi all,

Thanks you for your answer! But it doesn't work by me … I know that if you copie paste the code above it will work. I don't know why but the encoding change, but by me it doesn't work…

If I observe the to string they aren't the same. But the good question is why a string from the link in Indesign and an other from the file system is encoding different. I saw this post who explain that it is because the OSX:

Problem with UTF filenames on Mac OS X

If someone can help me I would appreciate!

Have a nice day:)

// test 1

var str = "Capture d’écran 2013-07-31 à 18.57.24.png";

var str2 = "Capture d’écran 2013-07-31 à 18.57.24.png";

str_encode = encodeURI (str_encode);

str_encode_2 = encodeURI (str_encode_2);

if(str_encode == str_encode_2){

    alert("string equal");

}

else{

    alert(str_encode);

    alert("string not equal");

}

// test 2

var str1 = "Capture%20d%E2%80%99%C3%A9cran%202013-07-31%20%C3%A0%2018.57.24.png";

var str2 = "Capture%20d%E2%80%99e%CC%81cran%202013-07-31%20a%CC%80%2018.57.24.png";

if(str1 == str2){

    alert("string equal 2");

}

else{

    alert("string not equal 2");

}

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 ,
Aug 19, 2013 Aug 19, 2013

But the good question is why a string from the link in Indesign and an other from the file system is encoding different.

@Bastien – I think this is made clear from the other thread you mentioned.
To speak it out: Adobe neglected to make it work and automatically "normalize" composite characters from OSX, if you read out file names from the OS with ExtendScript.

If you would work with AppleScript, there would be no problems in this regard.

To compair the two names, one derived from OSX directly, the other out of InDesign's Links Panel (or a list of file names imported from a spread sheet, a text file, InDesign itself etc.) in ExtendScript you first have to replace all possible composite characters with their single character representation.

One way is shown by Martin Fischer and Johannes Puff at hilfdirselbst.ch. I provided the links in the other thread.  Johannes expanded this with other composites.

Only after the replacement (replace() method with a regular expression), you are able to compair the two strings (file names) without problems.

Btw.: "ß" seems to be no problem!

There are other ways doing this. František Erben mentioned two.

Uwe

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
Explorer ,
Aug 20, 2013 Aug 20, 2013

Ok thanks… I understand…

I will replace the special char or ignore all file with spaces

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 ,
Aug 20, 2013 Aug 20, 2013

@Bastien – spaces (white space) in file names should be no problem at all…
Just the composites you encountered.

I did not test this:


I don't know if this will "normalize" composite characters in file names, but you could also write the list of file or path names to a text file with Unicode UTF-16 encoding and extract an array by reading it out, so you could compair with another array.

But I know that an UTF-16 encoding is required for the source txt or csv files for datamerge in InDesign if one is using eg. Umlauts in file names. Just discovered this and wrote about here:

Jim04:

Inserting an image from a CSV file

http://forums.adobe.com/message/5606395#5606395

I think, this wasn't one of the ways František Erben suggested.

One was something with hash tags and a text file, the other one was using a "Unicode Normalizer"…

But better ask for details  in the other thread:

František Erben:

Problem with UTF filenames on Mac OS X

http://forums.adobe.com/thread/1275272?tstart=0

Uwe

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
Explorer ,
Aug 24, 2013 Aug 24, 2013
LATEST

Thanks for the answer! I will reencode in UTF-16…

I don't have any time yet but when I find a solution I will poste it…

Bye.

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