Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 606641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:16:33+00:00 2026-05-13T17:16:33+00:00

I spent days working on a function to get common chars in an array

  • 0

I spent days working on a function to get common chars in an array of strings, in the right order, to create a wildcard.

Here is an example to explain my problem. I made about 3 functions, but I always have a bug when the absolute position of each letter is different.

Let’s assume “+” is the “wildcard char”:

Array(
0 => '48ca135e0$5',
1 => 'b8ca136a0$5',
2 => 'c48ca13730$5',
3 => '48ca137a0$5');

Should return :

$wildcard='+8ca13+0$5';

In this example, the tricky thing is that $array[2] as 1 char more than others.

Other example :

Array(
0 => "case1b25.occHH&FmM",
1 => "case11b25.occHH&FmM",
2 => "case12b25.occHH&FmM",
3 => "case20b25.occHH&FmM1");

Should return :

$wildcard='case+b25.occHH&FmM+';

In this example, the tricky parts are :
– Repeating chars, such as 1 -> 11 in the “to delete” part, and c -> cc in the common part
– The “2” char in $array[2] & [3] in the “to delete” part is not in the same position
– The “1” char at the end of the last string

I really need help because I can’t find a solution to this function and it is a main part of my application.

Thanks in advance, don’t hesitate to ask questions, I will answer as fast as possible.

Mykeul

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:16:33+00:00Added an answer on May 13, 2026 at 5:16 pm

    Main code:
    Step 1: Sort strings by length, shortest to longest, into array[]
    Step 2: Compare string in array[0] and array[1] to get $temp_wildcard
    Step 3: Compare string in array[2] with $temp_wildcard to create new $temp_wildcard
    Step 4: Continue comparing each string with $temp_wildcard – the last $wildcard is your $temp_wildcard

    OK, so now we’re down to the problem of how to compare two strings to return your wildcard string.

    Subroutine code:
    Compare strings character-by-character, substituting wildcards into your return value when the comparison doesn’t match.

    To handle the problem of different lengths, run this comparison an extra time for each character that the second string is longer with an offset. (Compare string1[x] to string2[x+offset].) For each returned string, count the number of wildcard characters. The subroutine should return the answer with the fewest number of wildcard characters.

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 507k
  • Answers 507k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In Python 3.x: >>> bytes([97]) b'a' May 16, 2026 at 4:09 pm
  • Editorial Team
    Editorial Team added an answer ILMerge takes a set of input assemblies and merges them… May 16, 2026 at 4:09 pm
  • Editorial Team
    Editorial Team added an answer Remove second SET from your insert query. it should like… May 16, 2026 at 4:09 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have spent the past couple of days working on this and am going
I spent the last three days working on the collection _ select form helper
I've spent the past few days working on updating my personal website. The URL
I'm working on some old AJAX code, written in the dark dark days before
I've spent the past few days at the school of hard knocks learning how
I'm using symfony 1.4 and doctrine. I've spent the last couple days playing with
I am currently working on an advanced web application that contains a number of
I'm having an incomprehensible problem in Scicoslab in the last few days. I've been
What's the best format for the JSON object for use in common Grids? I
I spend three days in find out how I can connect to an https

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.