If you have sex before marriage but you marry that person, is it still a sin? If that's the only person you had sex with is it still a sin? And another question: If you beg God to forgive your sins, how will you know if He forgives them?
"Marriage is honorable among all, and the bed undefiled; but fornicators and adulterers God will judge" (Hebrews 13:4).
Sex is undefiled, that is not sinful, within the bonds of marriage. It is sinful when you have sex without being married (fornication), or sex with someone other than your spouse (adultery). Therefore, once you are married, having sex with your spouse is no longer a sin.
However, getting married doesn't erase the fact that you had sinned. To gain forgiveness, a critical element is repenting of that sin. Repenting means changing your attitude about a sin -- accepting the fact that it is a sin -- and changing your behavior so you are no longer committing the sin.
If you are not truly a Christian, then you need to become one. "And such were some of you. But you were washed, but you were sanctified, but you were justified in the name of the Lord Jesus and by the Spirit of our God" (I Corinthians 6:11). Far too many people call themselves Christians without ever doing all that God said needs to be done to become one of His children. See: What Must I Do to be Saved?
If you are a Christian, God's solution is for the Christian to admit that he was wrong. "If we confess our sins, He is faithful and just to forgive us our sins and to cleanse us from all unrighteousness" (I John 1:9). That is all it takes. "My little children, these things I write to you, so that you may not sin. And if anyone sins, we have an Advocate with the Father, Jesus Christ the righteous" (I John 2:1). God also tells us that if you feel too unworthy to talk to God, or if you are concerned about overcoming sin, you can also enlist the aid of a faithful brother. "Confess your trespasses to one another, and pray for one another, that you may be healed. The effective, fervent prayer of a righteous man avails much" (James 5:16).
How do you know you've been forgiven? This too is simple. Do you know that you did as God asked? "Now by this we know that we know Him, if we keep His commandments. He who says, "I know Him," and does not keep His commandments, is a liar, and the truth is not in him. But whoever keeps His word, truly the love of God is perfected in him. By this we know that we are in Him. He who says he abides in Him ought himself also to walk just as He walked" (I John 2:3-6). It becomes a matter of whether you truly believe that God keeps His promises.