I would have said something more like this. Want to explode string.
$strings = explode("/", "Default Category/Diagrams/Business,Default Category/Diagrams/Strategy,Default Category/Diagrams/Planning,Default Category/Diagrams/Marketing,Default Category/Diagrams/Icons");
$categoryIds = [];
foreach($strings as $string) {
if($id = $this->getCategoryTitleFromId($string)) {
$categoryIds[] = $id;
}
}
Your method to load ID by string will look like this
public function __construct(
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $collectionFactory
) {
$this->collectionFactory = $collectionFactory ;
}
public function getCategoryTitleFromId($title) {
$collection = $this->collectionFactory
->create()
->addAttributeToFilter('name', $title)
->setPageSize(1);
if ($collection->getSize()) {
return $collection->getFirstItem()->getId();
}
return null;
}